2012-08-09 29 views
1

我花了几个小时努力使uploadify工作,但我看到的是一个按钮,说[选择文件],并什么都不做。发现一些链接,如Multiple file upload in MVC using UploadifyUsing uploadify with ASP.Net2导致相同。并且来自uploadify.com的信息也不起作用。所以我被卡在了uploadify上。MVC3:如何上传多个文件有或没有uploadify

我也注意到大部分信息至少有一年的历史。现在我想知道这是否是一种方法,或者你能推荐一种更好的方法吗?目前,我在看File upload asp.net mvc3它看起来真的很好,简单,但只允许你上传1个文件一次......

亲切的问候,

保罗。

+0

你能告诉我们你上传的代码是什么吗? – 2012-08-09 16:36:20

+0

我用plupload祝你好运。我已经在MVC3应用中使用它,并在客户端使用了每种方法(html5,flash,silverlight等)。 – BZink 2012-08-09 16:55:32

+0

我想知道你错过了菲尔哈克的[文章](http://haacked.com/archive/2010/) 07/16/uploadloading-files-with-aspnetmvc.aspx)?你用什么关键字搜索...... – Yasser 2012-08-09 17:45:44

回答

4

一种方法是:

根据菲尔哈克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"); 
} 

秒ond方式:

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

上传可用作文件输入元素的直接替换。

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

澄清: IE的版本不支持多个文件选择。

+1

这两种方法都可行。实际上,我们使用的是Telerik MVC扩展,它们是Kendo UI库的先驱,它们工作得很好。 – ryanulit 2012-08-09 16:55:18

+0

没错。我一个月前从Telerik迁移到Kendo UI扩展。 – 2012-08-09 17:02:56

+0

对不起,刚从假期回来。今天再试一次Uploadify,但仍不能正确工作。 Ofcourse传出了Phil Haack为多个文件提供的简单解决方案。确实2是一个倍数,但我希望能够真正选择多个,而不仅仅是2. – keun 2012-09-04 15:56:29