【发布时间】: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