我正在尝试通过 MVC3 简单地上传文件,这是我的视图:
@{
ViewBag.Title = "Pic";
Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}
@using (Html.BeginForm("FileUpload", "Blog", FormMethod.Post))
{
<input name="uploadFile" type="file" />
<input type="submit" value="Upload File" />
}
这是我的行动:
public ActionResult FileUpload()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
if (uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"),
Path.GetFileName(uploadFile.FileName));
uploadFile.SaveAs(filePath);
}
return View();
}
我的代码有什么问题??我有这个错误
Object reference not set to an instance of an object.
在这一行
if (uploadFile.ContentLength > 0)