This the html form:
<input id="picture1" name="Input_Pictures" type="file" value="" />
<input id="picture2" name="Input_Pictures" type="file" value="" />
<input id="picture3" name="Input_Pictures" type="file" value="" />
I also tried:
<input id="picture1" name="Input_Pictures[]" type="file" value="" />
<input id="picture2" name="Input_Pictures[]" type="file" value="" />
<input id="picture3" name="Input_Pictures[]" type="file" value="" />
and also too:
<input id="picture1" name="Input_Pictures[0]" type="file" value="" />
<input id="picture2" name="Input_Pictures[1]" type="file" value="" />
<input id="picture3" name="Input_Pictures[2]" type="file" value="" />
This is my view model:
public class PicturesInputViewModel
{
public IEnumerable<HttpPostedFileBase> Pictures { get; set; }
}
And this is the submit action:
[HttpPost]
public ActionResult Submit(PicturesInputViewModel input)
{
I can see the files in Request.Files
collection, but Pictures
is always null.
How can I solve this binding problem?
For the mean time I using this code successfully:
var pics = new List<HttpPostedFileBase>();
foreach (string name in Request.Files)
{
var file = Request.Files[name];
if (file.ContentLength > 0)
pics.Add(file);
}
input.Pictures = pics;