Razor页面上的kendo UI异步更新返回404

知识管理

我试图在Razor页面上使用Kendo UI异步上传(无控制器),但出现404错误

Index.cshtml页面

<div class="row">
    <div class="">
        <form asp-action="" class="" id=""  enctype="multipart/form-data">
            <div class="form-group">
                <label class="">Review Type</label>
                <div class="">               
                    <select asp-for="ReviewType" asp-items="@(new SelectList(Model.ReviewTypes, "ReviewTypeLookupId", "ReviewTypeName"))" class="form-control"></select>
                </div>
            </div>
            <div class="form-group">
                <label class=""></label>
                <div class="">
                    @(Html.Kendo().Upload()
                          .Name("files")
                          .Async(a => a
                            .Save("Index?handler=Save", "UploadManagement")
                              .Remove("Remove", "UploadManagement/Index")
                              .AutoUpload(true)
                          )
                          )
                </div>
            </div>
            <div class="form-group">
                <button type="submit" id="submit-all" class="btn btn-default">Upload </button>
            </div>
        </form>
    </div>  

Index.cshtml.cs页面

 [HttpPost]
        public ActionResult OnPostSave(IEnumerable<IFormFile> files)
        {
            // The Name of the Upload component is "files"
            if (files != null)
            {
                foreach (var file in files)
                {
                    //var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

                    //// Some browsers send file names with full path.
                    //// We are only interested in the file name.
                    //var fileName = Path.GetFileName(fileContent.FileName.Trim('"'));
                    //var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, "App_Data", fileName);

                    //// The files are not actually saved in this demo
                    ////file.SaveAs(physicalPath);
                }
            }

            // Return an empty string to signify success
            return Content("");
        }

错误-无法加载资源:服务器响应状态为404(未找到)

马可

解决此问题的最简单方法是不使用此方法.Save(string action, string controller)或对此进行任何重载,而是.SaveUrl(string url)

@(Html.Kendo().Upload()
    .Name("files")
    .Async(a => a
        .SaveUrl("./Index?handler=Save")
        .AutoUpload(true)
))

如果您位于非默认区域并且页面本身的网址是尖锐的,这也将起作用 /area-url/Index?handler=foo

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章