public ActionResult Index() { var vm = new InventoryViewModel(); vm.HandleRequest(); return(View(vm)); }
public ActionResult Index(InventoryViewModel vm) { vm.IsValid = ModelState.IsValid; // mvc sets this based on the data annotations vm.HandleRequest(); if (vm.IsValid) { ModelState.Clear(); } else { foreach (KeyValuePair <string, string> item in vm.ValidationErrors) { ModelState.AddModelError(item.Key, item.Value); } } return(View(vm)); }