【问题标题】:kendo UI asynchronous uplaod on Razor Page returns 404Razor 页面上的 kendo UI 异步上传返回 404
【发布时间】:2019-05-27 21:26:26
【问题描述】:

我正在尝试在 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(未找到)

【问题讨论】:

  • 对于剃须刀页面,您需要将路径设置为 Index?handler=Save 并将操作名称更改为 OnPostSave?
  • 做到了。但我仍然得到 404。请查看更新的代码。
  • 页面渲染时,url显示什么?
  • 如果该路径有效,则问题必须与模型绑定有关。我对剃须刀页面不太熟悉,但您不需要BindProperty 属性吗? stackoverflow.com/questions/50122555/… 也对此进行了讨论。

标签: asp.net-mvc asp.net-core kendo-asp.net-mvc razor-pages


【解决方案1】:

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

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

如果您在非默认区域并且页面本身的 url 实际上是 /area-url/Index?handler=foo

,这也将起作用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 2019-09-10
    • 2015-05-13
    • 2021-12-05
    相关资源
    最近更新 更多