【发布时间】:2014-03-06 18:44:14
【问题描述】:
我已经为上传文件创建了这个代码。但它不会在我创建的 App_Data/Uploads 文件夹中上传任何文件。 这是代码>>
In view>>
<form action="~/Views/Home/_SaveUpdate" 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>
And this my Handler>>
[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(HttpContext.Server.MapPath("~/App_Data/Uploads"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("Index");
}
请告诉我还需要做什么。另外,如何生成下载文件的链接。
【问题讨论】:
标签: asp.net-mvc http user-interface file-upload