public ActionResult Index() { TrainingProductViewModel vm = new TrainingProductViewModel(); vm.HandleRequest(); return View(vm); }
public ActionResult Index(TrainingProductViewModel vm) { vm.IsValid = ModelState.IsValid; vm.HandleRequest(); if (vm.IsValid) { // NOTE: Must clear the model state in order to bind // the @Html helpers to the new model values ModelState.Clear(); } else { foreach (KeyValuePair<string, string> item in vm.ValidationErrors) { ModelState.AddModelError(item.Key, item.Value); } } return View(vm); }