我正在使用Kendo.Upload上传IMG标签中的图片和临时视图。它非常适合镀铬。但在firefox和IE中有问题。在Firefox中,当我改变IMG标签的src时,我不会改变图像。在IE中,我将文件路径作为文件名来自FILE,而不是FILENAME。这是我的
HTML代码:
@Html.Kendo().Upload().Name("attachments").Async(async => async.Save("Save",
"DashboardConfiguration").AutoUpload(true)).Multiple(false)
.Events(e => e.Select("checksize").Success("onSuccess"))
.HtmlAttributes(new { accept = ".png,.jpg,.jpeg,.bmp" })
<img alt="Captcha" src="@Url.Action("pdfImage")" id="imgicon" />
的javascript
function onSuccess(e){
$('#imgicon').attr('src','');
$('#imgicon').attr('src','@Url.Action("pdfImage",
"DashboardConfiguration")');
}
控制器代码:
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments)
{
byte[] image = null;
// The Name of the Upload component is "attachments"
foreach (var file in attachments)
{
string filePath = Server.MapPath(General.FaxFolder + "/" + file.FileName);
file.SaveAs(filePath);
// Some browsers send file names with full path. We only care about the file name.
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
using (BinaryReader br = new BinaryReader(fs))
{
image = br.ReadBytes((int)fs.Length);
}
TempData["Image"] = image;
System.IO.File.Delete(filePath);
}
return Content("");
}
public ActionResult pdfImage()
{
var icon = (byte[])TempData["Image"];
return new FileStreamResult(new System.IO.MemoryStream(icon), "image/jpeg");
}
答案 0 :(得分:1)
您可以通过传递一个额外的变量来强制浏览器重新加载图像:
var d = new Date();
$('#imgicon').attr('src','');
$('#imgicon').attr('src','@Url.Action("pdfImage",
"DashboardConfiguration")' + "?" + d.getTime());