public ActionResult Products(DLProducts prod, string save, List <HttpPostedFileBase> postedFiles) { try { if (prod.ProductId == 0) { if (ModelState.IsValid) { return(View(prod)); } } else { if (!ModelState.IsValid) { return(View(prod)); } } int action; if (!String.IsNullOrEmpty(save)) { action = bal.Register(prod, "Insert"); } else { action = bal.Register(prod, "Update"); } if (action > 0) { int ProductId = 0; if (!String.IsNullOrEmpty(save)) { List <DLProducts> list = bal.LoadData(); DLProducts p = new DLProducts(); foreach (var l in list) { p = l; } ProductId = p.ProductId; } else { ProductId = prod.ProductId; } foreach (HttpPostedFileBase file in postedFiles) { if (file != null) { file.SaveAs(Server.MapPath("~/Content/Images/Products/" + file.FileName)); bool registerImage = bal.RegisterImage(ProductId, file.FileName); } } TempData["Error"] = "Data Added Succesfully"; } else { TempData["Error"] = "Something Happens Wrong !!!!"; } return(Redirect("/Product/Products")); } catch (Exception ex) { throw ex; } }