I am working on ASP.NET MVC web app.I want to upload multiple files on single input control. In my view:
<input type="file" name="files" multiple="multiple">
My model:
public HttpPostedFileBase[] files { get; set; }
Now, in my controller, I am trying to access each file as:
if (files[0] == null)
{
}
if (files[1] == null)
{
}
But if object is not present at that index, it's giving exception:
"Index was outside the bounds of the array."
So how to check if object is present at that index?
I cannot use foreach
because I want to treat each file separately. So is there any other option than foreach
to do this?
If you are going to treat the files differently, then I assume you know how to Identity each of the files separately. If this is so, why not name the files, something like this.
Then from your controller you can do this