【发布时间】:2022-02-02 21:11:29
【问题描述】:
我的 ASP.NET Core 6 应用程序有一个表单,用户可以在其中选择两个文件。提交表单时出现 400 错误:
Failed to load response data: No resource with given identifier found.
如果只选择一个文件,表单提交就可以正常工作。
我想知道为什么会发生这种情况以及如何解决。
HTML 表单:
<form id="submitFileUploadForm" asp-page-handler="FileSelected" method="post" enctype="multipart/form-data">
<input id="selectFileInput" name="SelectedFiles" asp-for="newLayer.SelectedFiles" type="file" multiple>
</form>
页面模型:
public IActionResult OnPostFileSelected(List<IFormFile> SelectedFiles)
{
//do something with SelectedFiles
}
型号:
public class NewLayer
{
public IEnumerable<IFormFile>? SelectedFiles { get; set; }
//various other properties
}
提交表单处理程序:
//submit form on file select
$("#selectFileInput").change(function () {
document.getElementById('submitFileUploadForm').submit()
});
【问题讨论】:
-
可以将单个文件添加到邮件正文中或作为附件。多个文件将仅作为附件添加。请参阅:docs.microsoft.com/en-us/previous-versions/office/developer/…
标签: c# html forms asp.net-core razor-pages