I’m new to MVC.NET and can’t seem to understand why my validate function is not being called which sits inside of a MyModel class.
MyModel:
Public string Name { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
// validation logic which is not being called on post.
}
When I post the form, I’m actually posting my ViewModel that has a property of MyModel.
ViewModel:
Public MyModel { get; set; }
Controller:
[HttpPost]
public ActionResult Index(ViewModel model)
{
// this is always true??
if(this.ModelState.IsValid) { blah blah }
}
The reason it’s always true is because my validation logic inside MyModel is not being called from the ViewModel on the POST.
This is probably a noob question but I have no idea. Thanks for any help.