加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – Kendo UI异步上传无法在Internet Explorer中运行

发布时间:2020-12-16 04:18:54 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试在异步模式下使用Kendo UI Upload(MVC包装器).事情似乎在Chrome中运行良好,但在IE中没有这样的运气(截至目前仅在IE 9中测试过).当它启动上传时,我可以看到它命中我的操作方法,并且请求包含我期望的数据,但实际上没有保存任何内容. 代码示例如下:
我正在尝试在异步模式下使用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" })))

控制器ActionMethod

[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集:

事实证明,当您在Internet Explorer中的HttpPostedFileBase上执行file.FileName时,它认为您需要本地计算机上文件的完整路径.它显然只是IE浏览器,因为Chrome和Firefox似乎都是正确的.

当您只需要实际的FileName时,请确保执行以下操作:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读