I currently have a form with multiple file inputs:
Resume: <input type="file" id="resume" name ="files" /><br />
Cover Letter: <input type="file" id="coverLetter" name ="files" /><br />
and in my back end:
[HttpPost]
public ActionResult Apply(ApplyModel form, List<HttpPostedFileBase> files)
{
if (!ModelState.IsValid)
{
return View(form);
}
else if (files.All( x => x == null))
{
ModelState.AddModelError("Files", "Missing Files");
return View(form);
}
else
{
foreach (var file in files)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/uploads"), fileName);
file.SaveAs(path);
<!--- HERE -->
}
}
}
}
My question is how do I determine if the file is from id resume or coverLetter in the spot at the commented HERE.
You can’t identify it. You need to use different names:
and then:
and to avoid lots of action parameters use a view model:
and then: