I have a multiple upload form and I want to check if there is any files when I launch the upload. Here is my code.
View :
@using (Html.BeginForm("Upload", "Home", FormMethod.Post,
new { enctype = "multipart/form-data"}))
{
<input name="files" type="file" multiple="multiple" />
<input type="submit" value="Upload" />
}
Controller :
[HttpPost]
public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
if (files.Count() > 0) Console.WriteLine(files.Count()); // display 1
if(files.Any()) Console.WriteLine(files.Any()); // display true
if (files.First() == null) Console.WriteLine("first null"); // display "first null"
return View();
}
Why my program display results like that when I submit an empty form ?
I'll probably check with JS my field, but I want to understand what is these data in my IEnumerable<HttpPostedFileBase>
. Thank you.