AFetter
AFetter

Reputation: 3584

How To upload Multiples Files MVC 3

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>&nbsp;</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

Answers (2)

Serj Sagan
Serj Sagan

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

GraemeMiller
GraemeMiller

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

Related Questions