我正在使用 Kendo.Upload 上传 IMG 标签中的图像和临时 View 。它非常适合 Chrome 。但在 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")');
}
Controller 代码:
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");
}
最佳答案
您可以通过传递额外的变量来强制浏览器重新加载图像,如下所示:
var d = new Date();
$('#imgicon').attr('src','');
$('#imgicon').attr('src','@Url.Action("pdfImage",
"DashboardConfiguration")' + "?" + d.getTime());
关于c# - 图像不会自动反射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24096726/