7

我正在尝试在异步模式下使用 Kendo UI Upload(MVC 包装器)。事情在 Chrome 中似乎运行良好,但在 IE 中没有这样的运气(目前仅在 IE 9 中测试)。当它启动上传时,我可以看到它击中了我的操作方法,并且请求包含我期望的数据,但实际上没有保存任何内容。

代码示例如下:

_EditForm.cshtml(上传的地方)

@(Html.Kendo().Upload()
    .Name(string.Format("upload{0}", "background"))
    .Multiple(true)
    .Events(evt => evt.Success("refreshBackgroundImages"))
    .Messages(msg => msg.DropFilesHere("drag and drop images from your computer here")
                        .StatusUploaded("Files have been uploaded"))
    .Async(a => a.AutoUpload(true)
                 .SaveField("files")
                 .Save("UploadImage", "Packages", new { siteId = Model.WebsiteId, type = "background" })))

控制器动作方法

[HttpPost]
public ActionResult UploadImage(IEnumerable<HttpPostedFileBase> files, Guid siteId, string type)
{
        var site = _websiteService.GetWebsite(siteId);
        var path = Path.Combine(_fileSystem.OutletVirtualPath, site.Outlet.AssetBaseFolder);
        if (type == "background")
        {
            path = Path.Combine(path, _backgroundImageFolder);
        }
        else if (type == "image")
        {
            path = Path.Combine(path, _foregroundImageFolder);
        }
        foreach (var file in files)
        {
            _fileSystem.SaveFile(path, file.FileName, file.InputStream, file.ContentType, true);
        }
        // Return empty string to signify success
        return Content("");
}
4

2 回答 2

8

Well as another post said, "Welcome to episode 52,245,315 of 'Why Does Internet Explorer suck so badly':

Turns out that when you do file.FileName on an HttpPostedFileBase in Internet Explorer, it thinks you want the whole path of the file on the local machine. It's obviously an IE only thing as Chrome and Firefox seem to have it right.

Make sure to do the following when you only want the actual FileName:

var filename = Path.GetFileName(file.FileName);
于 2013-07-11T17:47:57.323 回答
4

The problem is when you actually try to save a file and send back a success response from the server. I don't think your demos are doing any of that. The iframe in ie9 does not receive the response from the server. The browser thinks the response is a download even though it's just a plain text json response. I debugged it down to the fact that the on load event on the iframe never gets fired so the onload handler that needs to handle this response is not doing anything. In all other browsers this is working.

Source: http://www.kendoui.com/forums/kendo-ui-web/upload/async-uploader-and-ie-9-not-working.aspx

于 2013-07-08T14:17:27.113 回答