How to add many files to Form.Request.Files

Coreysan 1,631 Reputation points
2022-05-28T20:37:48.463+00:00

I have a project where I'm trying to simulate adding multiple files for upload to MVC.
Instead of using <input type=file multiple> a user would like to use several instances
of a dropzone, one for each image/thumbnail.

So imagine a page with 10 drop zones, where each drop zone would accept one selected file.

I saw a code snippet and wondered if I can modify it, and then somehow loop through all the file controls,
and add each file, one at a time, into a global formdata variable, sort of like this: (some pseudocode is included):

var data = new FormData();

for (int idx = 0; idx <= 9; idx)
{
    data.set("file", $("#uploadControl").val());    // Somehow add each data.set from 10 controls, maybe using data.append?????
}

$.ajax({
   type: "POST",
   url: "upload",
   data: data,
   contentType: false,
   processData: false
});
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,154 questions
{count} votes