我有一个ASP.NET MVC 3应用程序。我需要在其中实施文件上传器操作。出于某种原因,当我发布我的表单时,Request.Files集合是空的。我已经能够通过设置断点来确认这一点。所以我知道我正在采取行动。但是,我无法弄清楚为什么Request.Files集合是空的。这里是我的相关HTML,AreaRegistration和Controller片段。ASP.NET MVC 3 - 文件上传
的index.html
<form action="/files/upload/uniqueID" method="post" enctype="multipart/form-data">
<div>Please choose a file to upload.</div>
<div><input id="fileUpload" type="file" /></div>
<div><input type="submit" value="upload" /></div>
</form>
MyAreaRegistration.cs
context.MapRoute(
"FileUpload",
"files/upload",
new { action = "UploadFile", controller = "Uploader" }
);
UploaderController.cs
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadFile(int uniqueID)
{
foreach (string file in Request.Files)
{
// I never get here :(
}
return View();
}
我没有对默认的web.config文件进行任何更改。是否需要添加一些设置?我无法弄清楚为什么Request.Files集合是空的。有人可以帮帮我吗?
非常感谢!
你试过使用'Html.Form()'帮手? – jrummell 2012-01-10 13:21:16
[File upload MVC]的可能重复(http://stackoverflow.com/questions/765211/file-upload-mvc) – jrummell 2012-01-10 13:23:01