public ActionResult Test(DepartmentCreationVM data) { if (ModelState.IsValid) { return(RedirectToAction("Index")); } //ModelState.Clear(); ModelState["Budget"].Errors.Clear(); return(View(data)); }
public ActionResult Create(DepartmentCreationVM data) { if (ModelState.IsValid) { db.Department.Add(new Department() { Budget = data.Budget, Name = data.Name, StartDate = data.StartDate }); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(data)); }
public ActionResult Test(DepartmentCreationVM form) { if (ModelState.IsValid) { return(RedirectToAction("Index")); } //ModelState.Clear(); //ModelState.Remove("Budget"); //ModelState["Budget"].Errors.Clear(); //ModelState["Budget"].Value.AttemptedValue; //ModelState.Add() foreach (var item in ModelState["Budget"].Errors) { //item.ErrorMessage; } //ModelState.AddModelError("Budget", "My ERROR"); return(View(form)); }