I am trying to upload a single .csv file in ASP.NET MVC. In my .ascx file, I have:
<div>
<input type="file" name="file" id="file" />
   
<input type="submit" name="btnSubmit" id="btnSubmit" value="Upload" />
</div>
The controller action is:
public ActionResult Upload(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
return View();
}
The problem is that I always get file as Null in the Upload Action. Any suggestions on how to get this working?
Are you sure you have a
?
Edit :
method=”post”
+
on your action