I've this HTML:
<% using (Html.BeginForm("Upload", "BulkUpload", FormMethod.Post, new { enctype = "multipart/form-data" })) { %>
<%: Html.TextBoxFor(model => model.UploadFile, new { @type = "file" }) %>
<%: Html.ValidationMessageFor(model => model.UploadFile, "*") %>
<%= Html.Button("submit", "Upload", null) %>
<% } %>
And this Model:
public class BulkUploadVM
{
[DisplayName("File to import")]
public HttpPostedFileBase UploadFile { get; set; }
}
And this Controller:
[HttpPost]
public ActionResult Upload(BulkUploadVM model)
{
if (ModelState.IsValid)
{
var stream = model.UploadFile.InputStream;
// Process stream ...
}
return View("Index", model);
}
The upload file is correctly posted to the Controller, but when the Controller returns the View with the model (which has a valid UploadFile), the filepath is empty on the page ?
Is this default behavior ? Or Am I missing something ?