I have 2 different file inputs on the same view. I want to pass multiple files from file input A, and one from file input B. As of now, my code will allow me to pass the contents of A or B, but not both, to my controller. Thoughts on how to make this work? Please note that I am using MVC, and there are other inputs on the page, not just the file inputs.
There is some javascript that's not included that changes the text for the first input either to the name of the single file uploaded or it'll say '3 files selected'. Nothing special going on in javascript.
EDIT: Here is exactly what I want to do that I cannot do right now. I have 2 different file inputs that the user can upload to. I need both file inputs to pass back to the controller. Not just one file input. File input A has the multiple attribute. It can and does pass back multiple files. But that's not the issue is that only A or B will pass back the files that the user uploaded.
public class ViewDesigner
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
public List<File> Files { get; set; }
}
[HttpPost]
public ActionResult SignUp(ViewDesigner viewDesigner)
{
List<File> Files = new List<File>();
if (ModelState.IsValid)
{
for (int i = 0; i < Request.Files.Count; i++)
{
var requestedFile = Request.Files[i];
File file = new File()
{
FileName = requestedFile.FileName
};
Files.Add(file);
};
viewDesigner.Files = Files;
}
return View();
}
@using (Html.BeginForm("SignUp", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<b class="col-12">
Upload up to 5 documents
</b>
<small class="col-12">All files must be uploaded simultaneously.</small>
<div class="form-group col-lg-12 my-3">
<input type="file" id="file" name="file" accept="image/*, .gif, .xls, .doc, .docx, .pdf, .ppt" data-multiple-caption="{count} files selected" multiple="multiple" />
<label for="file"><i class="fad fa-upload"></i> <span>Choose a file…</span></label>
</div>
<b class="col-12">
Upload one document
</b>
<div class="form-group col-lg-12 my-3">
<input type="file" id="file2" name="file2" accept="image/*, .gif, .xls, .doc, .docx, .pdf, .ppt" />
<label for="file"><i class="fad fa-upload"></i> <span>Choose a file…</span></label>
</div>
}

