一種方法是:
根據菲爾哈克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的版本不支持多個文件選擇。
你能告訴我們你上傳的代碼是什麼嗎? – 2012-08-09 16:36:20
我用plupload祝你好運。我已經在MVC3應用中使用它,並在客戶端使用了每種方法(html5,flash,silverlight等)。 – BZink 2012-08-09 16:55:32
我想知道你錯過了菲爾哈克的[文章](http://haacked.com/archive/2010/) 07/16/uploadloading-files-with-aspnetmvc.aspx)?你用什麼關鍵字搜索...... – Yasser 2012-08-09 17:45:44