public ActionResult EditDieSheet(DieSheet c) { if (ModelState.IsValid) { try { articleRepository.Edit(c); articleRepository.Save(); return Json(new { redirectUrl = Url.Action("IndexDie") }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { Console.WriteLine(error); } } //If we come here, something went wrong. Return it back. //multi submit ViewBag.ActionMethod = "EditDieSheet"; return PartialView("_EditAndCreateDieSheet", c); }
public ActionResult EditDieSheet(string id) { DieSheet viewModel = new DieSheet(); viewModel = (DieSheet)articleRepository.GetSingle(id); //get producer and maker if (viewModel.CodArticle == "") return HttpNotFound(); //is used to know where we are from and go ViewBag.ActionMethod = "EditDieSheet"; return View("EditDieSheet", viewModel); }
public ActionResult CreateDieSheet(DieSheet c) { if (ModelState.IsValid) { try { c.CodArticle = articleRepository.GetNewCode(c, customerSupplierRepository, c.SupplierMaker, c.SupplierMaker); articleRepository.Add(c); articleRepository.Save(); return Json(new { redirectUrl = Url.Action("IndexDie") }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } //view name is needed for reach right view because to using more than one submit we have to use "Action" in action method name ViewBag.ActionMethod = "CreateDieSheet"; return PartialView("_EditAndCreateDieSheet", c); }