I can’t have asp.net mvc 1.0 to bind HttpPostedFileBase for me.
this is my EditModel class.
public class PageFileEditModel
{
public HttpPostedFileBase File { get; set; }
public string Category { get; set; }
}
and this is my edit method header.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection formCollection, PageFileEditModel[] pageFiles)
and this is my HTML
<input type="file" name="pageFiles[0].File" />
<input type="text" name="pageFiles[0].Category" />
<input type="file" name="pageFiles[1].File" />
<input type="text" name="pageFiles[1].Category" />
Category is bind correctly, but File is always null.
I’ve verifed that the files indeed are in Request.Files.
The HttpPostedFileBaseModelBinder is added by default so can’t figure out what is going wrong..
There’s a bug in MVC 1 (fixed in MVC 2 RC) where HttpPostedFileBase objects aren’t bound if they’re properties on your model type rather than parameters to your action method. Workaround for MVC 1:
That is, for each file upload element foo have a foo.exists hidden input element. This will cause the DefaultModelBinder’s short-circuiting logic not to kick in and it should correctly bind the HPFB property.