littlechris
littlechris

Reputation: 4184

Request.Files is empty when using input type file with ASP.Net MVC

When posting back to my controller my model is populated with correct values and my string field has the file name, but Request.Files is empty.

My input at the view is:

<input id="SitePlan" name="SitePlan" type="file" value="<%= Html.Encode(Model.SitePlan) %>" />

My form tag begins with:

 <% using (Html.BeginForm(new { enctype = "multipart/form-data" }))

Is there anything else I need to set to send the field back to the controller?

Upvotes: 11

Views: 12793

Answers (1)

David
David

Reputation: 15350

Have a look at the the <form> tag that is rendered. There is no Html.BeginForm declaration that just takes in the htmlAttributes that you are using. In fact, it uses the html attributes as routeValues. Try this...

<% using (Html.BeginForm("actionName", "controllerName", FormMethod.Post, 
   new { enctype = "multipart/form-data" })) { %>

Upvotes: 15

Related Questions