Reputation: 44295
Is it possible to conditionally validate a field with the server side validation helpers?
E.G.
public partial class SomeEntity
{
public bool Chargeable { get; set; }
[RegularExpression(@"\d{8,8}", ErrorMessage = "should have alpha numeric characters.")]
public string CaseNumber { get; set; }
}
Requirement: CaseNumber is required if and only if Chargeable is true.
I could do:
[RegularExpression(@"\d{8,8}", ErrorMessage = "should have alpha numeric characters."), Required]
public string CaseNumber { get; set; }
However, Required(if(Chargeable))
is what I need...
Upvotes: 0
Views: 61
Reputation: 990
Make your SomeEntity class implement the IValidatableObject interface.
Upvotes: 3