public ActionResult Create(SanPham sp) { try { // TODO: Add insert logic here SanPhamBus.Them(sp); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(sanpham sp) { //try //{ // TODO: Add insert logic here SanPhamBus.Them(sp); return(RedirectToAction("Index")); //} //catch //{ // return View(); //} }
public ActionResult Create(SanPham sp) { if (HttpContext.Request.Files.Count > 0) { var hpf = HttpContext.Request.Files[0]; if (hpf.ContentLength > 0) { string fileName = Guid.NewGuid().ToString(); string fullPathWithFileName = "/ShopOnline/img/" + fileName + ".jpg"; hpf.SaveAs(Server.MapPath(fullPathWithFileName)); sp.HinhAnh = fileName + ".jpg"; } } SanPhamBus.Them(sp); return(RedirectToAction("Index")); }