I have set the enctype to: multipart/form-data yet whenever I submit this form, the Request.ContentType is: application/x-www-form-urlencoded and the contents of the upload can't be retrieved from Request.Files.
Here is my View:
<% using (Html.BeginForm("Import", "Content", FormMethod.Post, new { enctype = "multipart/form-data" })) { %>
<p>
<%= Html.CheckBox("DeleteExisting")%> Delete Existing Records?
</p>
<p>
<input type="file" name="FileUpload" id="FileUpload" /> Select a dump file.
</p>
<p>
<input type="submit" value="Import Now" />
</p>
<% } %>
Here is my Action:
[HttpPost]
public ActionResult Import(FormCollection fc)
{
string chkDelete = fc["DeleteExisting"];
//string filename = fc["FileUpload"];
if (!chkDelete.Equals("false"))
{
//TODO: delete existing records, if specified
}
var inputFile = Request.Files["FileUpload"];
return View();
}
In the PostBack, the "fc" variable is filled and I can access the checkbox's value and can get the filename of the upload.
Why would my enctype be ignored?
I have tried manually putting the form tag in the view with the attributes in different positions, but that made no difference.
The only thing I can think is that this Import form is nested within the MasterPage's form, but that doesn't seem like it should be a problem. Plus I have this form enclosed properly.
Any suggestions?