2012-08-09 89 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