图像不会自动反射

本文关键字:反射 图像 | 更新日期: 2023-09-27 18:07:06

我正在使用剑道。上传用于上传图片和IMG标签中的临时视图。它适用于chrome。但是在firefox和IE中有问题。在firefox中,当我改变src的IMG标签,我不改变图像。在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");
}

图像不会自动反射

您可以通过传递一个额外的变量来强制浏览器重新加载图像,如下所示:

var d = new Date();
$('#imgicon').attr('src','');
$('#imgicon').attr('src','@Url.Action("pdfImage",
             "DashboardConfiguration")' + "?" + d.getTime());