My ASP.NET Core 6 app has a form in which users select two files. When the form is submitted I get a 400 error:
Failed to load response data: No resource with given identifier found.
The form submission works fine if only one file is selected.
I would like to know why this is happening and how to fix.
HTML form:
<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>
Page Model:
public IActionResult OnPostFileSelected(List<IFormFile> SelectedFiles)
{
//do something with SelectedFiles
}
Model:
public class NewLayer
{
public IEnumerable<IFormFile>? SelectedFiles { get; set; }
//various other properties
}
Submit form handler:
//submit form on file select
$("#selectFileInput").change(function () {
document.getElementById('submitFileUploadForm').submit()
});