Reputation: 3584
I need upload multiples files form MVC3. But I don't get the variable on the server. This is my code.
@using (Html.BeginForm("Index","Register", FormMethod.Post, new { enctype = "multipart/form-data" })) {
@Html.ValidationSummary(true)
<table>
<tr>
<td class="label">@Resources.Global.exemploFotos</td>
<td><input type="file" name="file" class="multi" accept="gif|jpg" maxlength="3" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="@Resources.Global.enviar" /></td>
</tr>
</table>
}
Controller:
[HttpPost] public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload, FormCollection collection)
{
return View();
}
But fileUpload == Null;
Upvotes: 3
Views: 2313
Reputation: 30208
Personally, to allow cross-browser compatibility for this I would use this answer: Uploading multiple images in the same form using MVC3
It's basically cloning your file upload input whenever someone selects a file in the last cloned file upload input
Upvotes: 0
Reputation: 12253
Change name of input to fileUpload. Your file input name is file. You are then looking for fileUpload to populate your IEnumerable of files.
Upvotes: 5