Uploading image in ASP.NET MVC

Firstly, you’ll need to change your view to include the following:

<input type="file" name="file" />

Then you’ll need to change your post ActionMethod to take a HttpPostedFileBase, like so:

[HttpPost]
public ActionResult Create(tblPortfolio tblportfolio, HttpPostedFileBase file)
{
    //you can put your existing save code here
    if (file != null && file.ContentLength > 0) 
    {
        //do whatever you want with the file
    }
}

Leave a Comment