HttpPostedFile is null

So you have your action ready to receive your data from your HTML file inputs but the array values for the files are coming in as null?

//Controller
public ActionResult Save(MyModel model, HttpPostedFileBase[] attachedFiles)
{
   //...
}

Just add enctype = "multipart/form-data" to your form tag.

//View
@using (Html.BeginForm("Save", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" })) {
   //...
   
   
   
   //...
}

Notice the anonymous object is AFTER the FormMethod parameter! Excluding this parameter will pass the object in as the action parameters, not HTML attributes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s