一個也不想要使用Request.Files的向後兼容性如下:
public ActionResult UploadFiles()
{
string UpoadedFilesFolder = "YourServerFolder";
string fileName ="";
byte[] fileData=null;
foreach (HttpPostedFileBase uf in Request.Files)
{
HttpPostedFileBase UpoadedFile = uf;
if (uf.ContentLength > 0)
{
fileName = Path.GetFileName(UpoadedFile.FileName);
using (BinaryReader br = new BinaryReader(UpoadedFile.InputStream))
{
fileData = br.ReadBytes((int)UpoadedFile.InputStream.Length);
}
using (FileStream fs = new FileStream(Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath(UpoadedFilesFolder), fi.FileName), FileMode.Create))
{
fs.Write(fileData, 0, fileData.Length);
}
}
}
return Content("OK");
}
的可能重複[多文件上傳與HTML 5](http://stackoverflow.com/questions/8713802/multi-file-upload-with-html-5) – 2012-01-09 00:23:59
您可能需要創建自定義模型聯編程序。 – Craig 2012-01-09 00:28:40
或者使簽名'公衆ActionResult上傳(HttpPostedFileBase []文件)' – 2012-01-09 00:31:50