Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 708
littlechris Avatar asked Sep 04 '09 21:09

littlechris


1 Answers

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" })) { %>
like image 199
David Avatar answered Nov 01 '22 01:11

David