When I attempt to upload images to my MVC controller action and there is a validation error, I have to click through each of the buttons and find all of my files again.
If I have a view that consists of
<input type="file" id="file0" name="Files[0]" />
<input type="file" id="file1" name="Files[1]" />
and a controller action like
public ActionResult Create(ModelClass model, IEnumerable<HttpPostedFileBase> Files)
{
if(ModelState.IsValid)
{
//do work
if(PhotoValidation.IsValid(Files))
{
//do work
}
else
{
ModelState.AddModelError("","Photos not valid");
}
}
return view(model); // Way to return photos back to the view on modelstate error?
}
The files get posted to the server fine but if there is a model validation error, is there any way to return the model AND the Files so the user doesn't have to upload them again?