2012-02-06 83 views
3

我需要從MVC3上傳多個文件。但是我沒有得到服務器上的變量。這是我的代碼。如何上傳多個文件MVC 3

@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> 
    } 

控制器:

[HttpPost] public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload, FormCollection collection) 
{ 
     return View(); 
} 

但是文件上傳== NULL;

+0

這是好的解決方案http://midnightprogrammer.net/post/Upload-Files-In-RAZOR-With-jQuery-Uploadify-Plugin.aspx – cpoDesign 2012-02-06 16:03:22

回答

5

更改fileUpload的輸入名稱。您的文件輸入名稱是文件。然後,您正在尋找fileUpload來填充您的IEnumerable文件。

+0

男人,你是一個天才!謝謝。 – AFetter 2012-02-06 16:00:25

+1

沒問題。另外一般來說,如果你正在做文件上傳,我傾向於喜歡http://www.plupload.com/control。 – GraemeMiller 2012-02-06 16:02:20

+0

有什麼我可以添加到此答案來幫助?你的問題解決了嗎?如果是這樣你能接受答案:) – GraemeMiller 2012-02-07 15:16:49

0

就個人而言,考慮到這一點,我會用這個答案跨瀏覽器的兼容性:Uploading multiple images in the same form using MVC3

它基本上是克隆你的文件上傳輸入每當有人選擇在過去的克隆文件上傳輸入文件

+0

非常好。謝謝。 – AFetter 2013-11-09 06:58:52