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;

1

2 Answers 2

5

Change name of input to fileUpload. Your file input name is file. You are then looking for fileUpload to populate your IEnumerable of files.

Sign up to request clarification or add additional context in comments.

2 Comments

No problem. Also in general if you are doing file uploads I tend to like plupload.com control.
Is there anything I can add to this answer to help? Is your issue resolved. If so can you accept the answer :)
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.