我有一个上传文件的应用程序,我做了这个视图:
@{
ViewBag.Title = "Upload a projet";
}
<section id="logout">
@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })) {
@Html.AntiForgeryToken()
<a href="@Url.Action("Logout", "Akeo")" >Se déconnecter</a>
}
</section>
@using (Html.BeginForm("Uploading_validation", "Akeo", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="dossier" />
<br />
<input type="submit" value="OK" />
}
那个行动Uploading_validation
[HttpPost]
public ActionResult Uploading_validation()
{
HttpPostedFileBase fileurl = null;
foreach (string file in Request.Files)
{
fileurl = Request.Files[file];
}
// Verify that the user selected a file
if (fileurl != null && fileurl.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(fileurl.FileName);
// store the file inside ~/App_Data/uploads folder
var path = @"C\Inetpub\wwwroot\"+fileName;
fileurl.SaveAs(path);
}
// redirect back to the index action to show the form once again
return RedirectToAction("Index");
}
即使我选择一个文件参数file
总是空的问题!
这是什么原因?如何修改代码以修复此错误?