How to add many files to Form.Request.Files
Coreysan
1,631
Reputation points
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
});