That makes no sense to me.
Take a look at this ViewModel:
public class SelectService
{
[Required]
public int? SelectedServiceId { get; set; }
}
Take a look at this action:
[HttpPost]
public virtual ActionResult SelectService()
{
TryUpdateModel(WizardContainer.SelectService, "SelectService");
TryValidateModel(WizardContainer.SelectService, "SelectService");
if (ModelState.IsValid)
{
return RedirectToAction("OtherAction");
}
else
{
return View(WizardContainer);
}
}
Now read this exceprt from Apress ASP.NET MVC 2 Framework by S. Sanderson:
Whenever you use model binding to populate a model object - either by obtaining a parameter as an action method or by manually calling UpdateModel () or TryUpdateModel (), then DefaultModelBinder will automatically launch validators associated with all the model objects that it has updated ( i.e. those where he set the value to at least one property). If you update the model object in any other way, its validators will not be executed unless you explicitly specify the framework for their launch.
, , TryUpdateModel()? , TryValidateModel().
UPDATE
, :
[HttpPost]
public virtual ActionResult Index(string nextButton)
{
TryUpdateModel(WizardContainer.Index);
if (nextButton != null && ModelState.IsValid)
{
return RedirectToAction("OtherAction");
}
else
{
return View(WizardContainer.Index);
}
}
ViewModel:
public class Index
{
[Required]
public DateTime? SelectedServiceTime { get; set; }
}
2
, , , , .
:
[HttpPost]
public virtual ActionResult SelectService()
{
TryUpdateModel(WizardContainer.SelectService);
if (ModelState.IsValid)
{
return RedirectToAction("OtherMethod");
}
else
{
return View(WizardContainer.SelectService);
}
}
, , TryUpdateModel(), , , , . ?