我的图像控件如下:
<img src="@Url.Action("GetProfileImage", "Controller", new { id = Model.DocId})"动作
public FileResult GetProfileImage(int id)
{
var usr = new Whatever();
byte[] barrImg = usr.GetProfilePhoto(id);
return File(barrImg, "image/png");
}我的save方法是这样的:
function SavePhotoToDb() {
var json;
var data;
$.ajax({
type: "POST",
url: "/Example/SaveProfilePhoto",
data: new FormData($("#form0").get(0)),
dataType: "html",
contentType: false,
processData: false,
success: saveItemCompleted(data),
error: saveItemFailed
});
}
function saveItemCompleted(data) {
//showing success notification;
// what else I have to do here to display the new image
}这是工作正常的时候,页面加载了所有上传的个人资料照片。但是当上传新照片时,它应该显示新照片,但当我上传新照片时,它不会触发GetProfileImage()操作,即使我删除了照片,它也会从sql server中删除,但页面仍然显示该照片。
我上传一张新照片时应该怎么做才能显示新照片,删除照片时应该怎么做才能不显示照片,因为我已经删除了照片。
发布于 2013-10-24 00:44:56
您可以向img标签添加id
<img id="myimage" src="@Url.Action("GetProfileImage", "Controller", new { id = Model.DocId})"在JS函数中
function saveItemCompleted(data) {
//Force to reloaded image
var image = new Image();
image.src = $("#myimage").attr("src") + "?_=" + (new Date().getTime()) ;
$("#myimage").attr("src", image.src)
}https://stackoverflow.com/questions/19541886
复制相似问题