I tried to have an images uploader but when I click the browse and select image then submit my form the HttpPostedFileBase is null. Is there missing with my implementation? Please help.
View
<form action="Home/UploadImage" method="POST">
<p>
<input type="file" accept="image/x-png, image/gif, image/jpeg" name="projectBgImage" id="projectBgImage"/>
</p>
<input type="submit" value="submit"/>
</form>
Home Controller
public ActionResult UploadImage(HttpPostedFileBase projectBgImage)
{
return View();
}
Debug Image
add
enctype attribute
yourform
elementI suggest you to use
BeginForm
html-helper like this:and Action Method with
[HttpPost]
annotationExtra Information : A nice blog post by Phil Haack Asp.net MVC Upload
In the View an
enctype
attribute is required to be set tomultipart/form-data
Second, On top of your action method make sure you have the
HTTPPOST
attribute.