public ActionResult Create(MeubleVm meubleVM, HttpPostedFileBase file) { Meuble A = new Meuble(); A.Titre = meubleVM.Titre; A.DatePublication = DateTime.UtcNow; A.IdMeuble = meubleVM.IdMeuble; A.Description = meubleVM.Description; A.Image = file.FileName; A.PrixM = meubleVM.PrixM; A.Adresse = meubleVM.Adresse; var fileName = ""; if (file.ContentLength > 0) { var path = Path.Combine(Server.MapPath("~/Content/"), file.FileName); file.SaveAs(path); } // return RedirectToAction("CreateM"); //} //else A.UserID = User.Identity.GetUserId(); meubleService.Add(A); meubleService.Commit(); //var path = Path.Combine(Server.MapPath("~/Content/Upload/"), Image.FileName); //Image.SaveAs(path); return(RedirectToAction("AfficherMeuble")); }
public ActionResult Create(Meuble MVM, HttpPostedFileBase file) { try { MVM.Image = file.FileName; if (file.ContentLength > 0) { var path = Path.Combine(Server.MapPath("~/Content/"), file.FileName); file.SaveAs(path); } Service.Add(MVM); Service.Commit(); return(RedirectToAction("Index")); } catch (Exception e) { return(Json(e.Message)); } }