我是MVC 4的新手,正在尝试在我的网站中实施文件上传控制。我找不到错误。我的文件中出现空值。
控制器:
public class UploadController : BaseController
{
public ActionResult UploadDocument()
{
return View();
}
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
file.SaveAs(path);
}
return RedirectToAction("UploadDocument");
}
}
视图:
@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="FileUpload" />
<input type="submit" name="Submit" id="Submit" value="Upload" />
}
文件上载ASP.NET MVC 3.0的
—
Liam
您只需要更改公共ActionResult Upload(HttpPostedFileBase文件)<input type =“ file” name =“ FileUpload” />
—
Hafiz Asad
错过
—
Savage
enctype
表格花了我一个小时
Upload()方法和按钮之间的连接在哪里。应该有一个onClick事件吗?我是asp.net的新用户
—
pnizzle '18