Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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?

share|improve this question
    
What is in Model.SitePlan? I believe most browsers will not allow you to assign a default value to an <input type="file" />, but I am not sure if this is related to the problem you are facing. – Jørn Schou-Rode Sep 4 '09 at 21:15
    
I'm having the same problem, but my using statement looks like the answer: @using (Html.BeginForm("UploadPatientFiles", "Wizard", FormMethod.Post, new { id = "uploadForm", enctype = "multipart/form-data" })) Any other reasons this could be happening? – Dan Csharpster Aug 18 '14 at 20:13
up vote 15 down vote accepted

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" })) { %>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.