public ActionResult Add(Products_Table productTable) { string fileName = Path.GetFileNameWithoutExtension(productTable.ImageFile.FileName); string extension = Path.GetExtension(productTable.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; productTable.Product_Image = URL + "/Image/" + fileName; fileName = Path.Combine(Server.MapPath("/Image/"), fileName); productTable.ImageFile.SaveAs(fileName); db.products.Add(productTable); db.SaveChanges(); ModelState.Clear(); return(View()); }
public ActionResult Create([Bind(Include = "ID,ImageFile,Product_Name,Product_Desc,Product_Price")] Products_Table product) { if (ModelState.IsValid) { string fileName = Path.GetFileNameWithoutExtension(product.ImageFile.FileName); string extension = Path.GetExtension(product.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; product.Product_Image = URL + "/Image/" + fileName; fileName = Path.Combine(Server.MapPath("/Image/"), fileName); product.ImageFile.SaveAs(fileName); db.products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }