I use the validation attribute on the fields of a class and has a requirement like that:
if field ‘a’ is validate succeed then process the validation of field ‘b’ but if the field ‘a’ is not throw validation , ignore the validation of field ‘b’.
does it feasible or i should think in other way?
public class myclass
{
[required]
public string a{get;set;}
[required]
public string b{get;set;]
}
i want:
1.if a pass the validate, then execute b ‘s validate
2.if a not pass the validate , then don’t execute the b ‘s validate
Check out the MVC.ValidationToolkit
http://blogs.msdn.com/b/simonince/archive/2011/09/29/mvc-validationtookit-alpha-release-conditional-validation-with-mvc-3.aspx
It contains these two validations that will help you out.