如何上传多个文件 MVC 3

3

我需要从MVC3上传多个文件。但是我在服务器上没有获取到变量。这是我的代码。

@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();  
}

但是fileUpload == Null;

这是一个不错的解决方案:http://midnightprogrammer.net/post/Upload-Files-In-RAZOR-With-jQuery-Uploadify-Plugin.aspx - cpoDesign
2个回答

5

将输入的名称更改为fileUpload。您的文件输入名称为file。然后,您要寻找fileUpload来填充您的文件IEnumerable。


1
没问题。一般来说,如果您正在进行文件上传,我倾向于使用http://www.plupload.com/控件。 - GraemeMiller
有什么我可以补充到这个答案来帮助您吗?您的问题解决了吗?如果是的话,您可以接受这个答案 :) - GraemeMiller

0

个人而言,为了实现跨浏览器兼容性,我会使用以下答案:使用MVC3上传多个图像的同一表单

基本上,每当有人在最后一个克隆的文件上传输入中选择文件时,它就会克隆您的文件上传输入。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接