I'm trying to simply Upload file via MVC3 this is my View :
@{
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" />
}
and this is my actions :
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();
}
what is wrong with my code ?? I have this Error
Object reference not set to an instance of an object.
in this line
if (uploadFile.ContentLength > 0)