【问题标题】:MVC3: how to upload multiple files with or without uploadifyMVC3:如何使用或不使用uploadify上传多个文件
【发布时间】:2012-08-09 16:28:40
【问题描述】:

我花了几个小时试图让 uploadify 工作,但我看到的只是一个按钮,上面写着 [选择文件],但什么也没做。找到一些链接,如 Multiple file upload in MVC using UploadifyUsing uploadify with ASP.Net2 导致相同的结果。使用uploadify.com 的信息,它也不起作用。所以我被困在uploadify。

我还注意到大多数信息至少有一年的历史。现在我想知道这是否是要走的路,或者你能推荐一个更好的方法吗?目前我正在查看File upload asp.net mvc3,它看起来非常漂亮和简单,但一次只能上传一个文件......

亲切的问候,

保罗。

【问题讨论】:

  • 你能分享一下你上传的代码吗?
  • 我的 plupload 很幸运。我在 MVC3 应用程序中使用过它,并在客户端上使用过每种方法(html5、flash、silverlight 等)。
  • 我想知道你是怎么错过 Phil Haack 的 article 的?您用于搜索的关键字..
  • 是的,它来了。但我希望能够上传多个,不限于2个。
  • 我现在将调查 plupload。没有遇到那个。感谢您的提示。

标签: jquery asp.net-mvc-3 file-upload uploadify


【解决方案1】:

一种方法是:

根据菲尔哈克http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx

你可以这样做:

<form action="" method="post" enctype="multipart/form-data">

 <label for="file1">Filename:</label>
 <input type="file" name="files" id="file1" />

 <label for="file2">Filename:</label>
 <input type="file" name="files" id="file2" />

 <input type="submit"  />
 </form>

还有控制器..

[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files) {
 foreach (var file in files) {
 if (file.ContentLength > 0) {
   var fileName = Path.GetFileName(file.FileName);
   var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
   file.SaveAs(path);
 }
}
return RedirectToAction("Index");
}

第二种方法:

使用 KendoUI 的上传。它允许同步和异步上传多个文件。

上传可以用作文件输入元素的替代品。

http://demos.kendoui.com/web/upload/index.html

澄清:没有IE版本支持多文件选择。

【讨论】:

  • 这两种方法都可以。实际上,我们在工作中使用了 Telerik MVC 扩展,它是 Kendo UI 库的前身,并且运行良好。
  • 没错。一个月前,我从 Telerik 迁移到了 Kendo UI 扩展。
  • 抱歉,刚放假回来。今天再次尝试 Uploadify,仍然无法正常工作。当然,遇到了 Phil Haack 的多文件简单解决方案。确实 2 是一个倍数,但我希望能够真正选择多个,而不仅仅是 2。
  • @keun 我刚刚尝试了剑道上传的演示,可以选择 3 个文件。你看到这个了吗? demos.kendoui.com/web/upload/async.html
  • @Pabloker 是的,看到了。但是该对话框每次只能让我选择 1 个文件。第二次单击选择按钮时,我可以选择另一个。例如,当我想要 20 个时有点麻烦。
猜你喜欢
  • 2011-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多