I installed enctype for: multipart / form-data, but whenever I submit this form, Request.ContentType: application / x-www-form-urlencoded and the contents of the download cannot be obtained from the .files request.
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(); }
The variable "fc" is populated in PostBack, and I can access the checkbox value and get the file name to upload.
Why will my enctype be ignored?
I tried to manually put the form tag in the view with attributes in different positions, but that didn't matter.
The only thing I can think of is that this import form is nested in the MasterPage form, but it does not look like this should be a problem. Plus I have this form, properly enclosed.
Any suggestions?
source share