public ActionResult Upload(int recipeId, HttpPostedFileBase file) { string fileName = ""; // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the filename fileName = Path.GetFileName(file.FileName); // store the file inside ~/App_Data/uploads folder var path = Path.Combine(Server.MapPath("~/Img/"), fileName); file.SaveAs(path); recipeDal.AddImage(fileName, recipeId); } // redirect back to the index action to show the form once again return(RedirectToAction("Admin")); }