Dave
Dave

Reputation: 1775

File input empty but an empty "file" shows up in Request.Files

I have a view that has the following file input:

<input type="file" name="SchemaFiles" id="SchemaFiles" class="form-control" multiple/>

My model has this attribute:

  public List<HttpPostedFileBase> SchemaFiles { get; set; }

When I select one or two files for this input, everything works fine. However, if I don't select any files and submit the form, then SchemaFiles.Count is 1, and SchemaFiles[0] is null (but does exist). ModelState.IsValid is true.

Is there a way to avoid this?

Upvotes: 3

Views: 1129

Answers (1)

Haukman
Haukman

Reputation: 3776

This is by-design and looks like the root cause is the browser. See these links for reference:

Upvotes: 2

Related Questions