I'm trying to upload picture to a folder. I have already try all answers here. Here is my code:
Controller:
[HttpPost]
public ActionResult UploadImage(HttpPostedFile uploadFile)
{
if (uploadFile != null)
{
string ImageName = System.IO.Path.GetFileName(uploadFile.FileName);
string Path = Server.MapPath("~/Content/Images/" + ImageName);
// save image in folder
uploadFile.SaveAs(Path);
db.SaveChanges();
}
return View();
}
View:
@using (Html.BeginForm("UploadImage", "Quizs", FormMethod.Post, new { enctype = "multipart/form-data " }))
{
<div>
<input type="file" name="uploadFile" /> <br />
<input type="submit" value="Upload" />
</div>
}
When I submit that form i get NULL in Controller (uploadFile is null). Please help me and tell me what is wrong.
Thank you
HttpPostedFileBase uploadFile. You also have an extra space innew { enctype = "multipart/form-data " }