I use this method to upload image and save it to a folder i created in the server :
public ActionResult Create(Regional regional, HttpPostedFileBase صورة) { if (ModelState.IsValid) { if (صورة != null) { صورة.SaveAs(Path.Combine(Server.MapPath("~/1"), صورة.FileName)); regional.صورة = صورة.FileName; } db.Regionals.Add(regional); db.SaveChanges(); return RedirectToAction("Index"); } return View(regional); }
and the input is :
<input type="file" id="صورة" name="صورة" accept="image/*" >
But The problem is when i press submit, the name of the image is saved in Database but the picture is not saved to the sever, i can't find it in the folder that i created which is named "1"
please any help
regional.صورة
is set withFileName
, not the path. Maybe you prefix with the folder, likeregional.صورة = Path.Combine("1", صورة.FileName);