How come module-level validators are evaluated only after property-level validators?
Posted
by jonathanconway
on Stack Overflow
See other posts from Stack Overflow
or by jonathanconway
Published on 2010-05-30T04:19:42Z
Indexed on
2010/05/30
4:32 UTC
Read the original article
Hit count: 336
I'm using the module-level validator: 'PropertiesMustMatch' on my view-model, like so:
[PropertiesMustMatch("Password", "PasswordConfirm")]
public class HomeIndex
{
[Required]
public string Name { get; set; }
public string Password { get; set; }
public string PasswordConfirm { get; set; }
}
I'm noticing that if I submit the form without Name filled in, the ValidationSummary() helper returns only the following error:
- The Name field is required.
However, if I fill in Name, then ValidationSummary() will return a PropertiesMustMatch error:
- 'Password' and 'PasswordConfirm' do not match.
So it looks like the property-level validators are being evaluated first, then the model-level validators.
I would much prefer if they were all validated at once, and ValidationSummary would return:
- The Name field is required.
- 'Password' and 'PasswordConfirm' do not match.
Any ideas what I can do to fix this?
I'm studying the MVC 2 source-code to try to determine why this happens.
© Stack Overflow or respective owner