11

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?

2
  • 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. Commented Sep 4, 2009 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? Commented Aug 18, 2014 at 20:13

1 Answer 1

15

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" })) { %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.