This project is read-only.

Why IEnumerable<HttpPostedFileBase> count is 1 when I upload 0 files?

Apr 29, 2014 at 4:08 AM
Edited Apr 29, 2014 at 10:37 AM
Is it the known issue?

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 :
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.

I did a few research on this and posted them on my blog . If it's not the by-design issue then I like to contribute the patch for this. I contributed it once for EF so you guys already have my signed paper.
May 8, 2014 at 8:05 AM
Any update? guys
May 8, 2014 at 7:34 PM

This is by design. This is part of System.Web and so we are not too inclined to fix this issue currently. A similar related issue was filed against Web API. You can check the resolution information on it.

May 9, 2014 at 2:01 AM
Great! Thanks!