c# - 图像不会自动反射

标签 c# javascript jquery asp.net-mvc kendo-asp.net-mvc

我正在使用 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/

相关文章:

c# - 将 3 维数组复制到 11x3 维数组 C#

c# - 默认值设置为 0 的输入在没有 0 的情况下呈现

c# - 使用哪个音频库?

javascript - 当需要 express 时,它是一个函数还是一个对象?

jquery - 使用 CSS 和 Jquery 循环排列元素

c# - 为什么我的应用程序将 24% 的生命周期用于空值检查?

javascript - 如何检查隐藏字段是否没有值?

javascript - 打开弹出窗口并在关闭弹出窗口时刷新父页面

javascript - 通过使用 jquery 检查选​​中哪个单选按钮来执行事件

javascript - 我需要在 ajax 响应后重新创建多选