Asp.net-Mvc

Kendo UI 非同步上傳在 Internet Explorer 中不起作用

  • July 11, 2013

我正在嘗試在非同步模式下使用 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("");
}

正如另一篇文章所說,“歡迎收看‘為什麼 Internet Explorer 如此糟糕’的第 52,245,315 集:

事實證明,當您file.FileName在Internet Explorer 中執行操作時,它認為您想要本地電腦HttpPostedFileBase上文件的整個路徑。這顯然是 IE 唯一的東西,因為 Chrome 和 Firefox 似乎是正確的。

當您只需要實際 時,請確保執行以下操作FileName

var filename = Path.GetFileName(file.FileName);

問題是當您實際嘗試保存文件並從伺服器發回成功響應時。我不認為你的展示在做任何事情。ie9 中的 iframe 沒有收到伺服器的響應。瀏覽器認為響應是下載,即使它只是純文字 json 響應。我將其調試為 iframe 上的 onload 事件永遠不會被觸發,因此需要處理此響應的 onload 處理程序沒有做任何事情。在所有其他瀏覽器中,這都有效。

來源:http ://www.kendoui.c​​om/forums/kendo-ui-web/upload/async-uploader-and-ie-9-not-working.aspx

引用自:https://stackoverflow.com/questions/17528674