public ActionResult Input(Product model, HttpPostedFileBase uploadFile) { // Up anh if (uploadFile != null) { string fileName = $"{DateTime.Now.Ticks}{Path.GetExtension(uploadFile.FileName)}"; // string _fileName = string.Format{"{0}{1}"} $"{DateTime.Now.Ticks}{Path.GetExtension(uploadFile.FileName)}"; // string _FileName = Path.GetFileName(uploadFile.FileName); string filePath = Path.Combine(Server.MapPath("~/Images"), fileName); uploadFile.SaveAs(filePath); model.PhotoPath = fileName; } try { if (string.IsNullOrEmpty(model.ProductName)) { ModelState.AddModelError("ProductName", "ProductName expected"); } if (string.IsNullOrEmpty(model.QuantityPerUnit)) { ModelState.AddModelError("QuantityPerUnit", "QuantityPerUnit expected"); } if (string.IsNullOrEmpty(model.Descriptions)) { model.Descriptions = ""; } if (string.IsNullOrEmpty(model.PhotoPath)) { model.PhotoPath = ""; } if (!ModelState.IsValid) { ViewBag.Title = model.SupplierID == 0 ? "Create new Product" : "Edit a Product"; return(View(model)); } if (model.ProductID == 0) { CataLogBLL.AddProduct(model); } else { CataLogBLL.UpdateProduct(model); } return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("Loi", ex.StackTrace); return(View(model)); } }