I’m passing from my view page one to five images to controller.
<input type="file" name="Images" /><br />
<input type="file" name="Images" /><br />
<input type="file" name="Images" /><br />
<input type="file" name="Images" /><br />
<input type="file" name="Images" /><br />
I receive on my controller like this
IEnumerable<HttpPostedFileBase> images
and sending this data together with other data to myDomainModel
I tried with this
List<Photo> Photos = new List<Photo>();
for (int i = 0; i < Images.Count(); i++)
{
foreach (var image in Images)
{
Photo p = new Photo();
p.ImageMimeType = image.ContentType;
p.ImageData = new byte[image.ContentLength];
image.InputStream.Read(p.ImageData, 0, image.ContentLength);
Photos.Add(p);
}
}
But Images.Count() return capacity of whole list, so when I’m post let say 2 images instead of five I’m in trouble cause code trying to loop 5 times.
So, question is how to get number of elements in list. Not capacity.
Thank you.
It’s not quite clear what is going on. It sounds like the source page is adding empty images that the user didn’t submit? If that’s the case, then you it would be better to fix this there.
Failing that, then this should work: