In a ASP.NET MVC4 application we are using FluentValidation for validating our models. In certain cases we only want to validate a property when another property has a value. We use the When keyword to accomplish this. A simple validation class looks like this:
public class PersonValidator : AbstractValidator<Person>
{
public PersonValidator()
{
RuleFor(item => item.FirstName).NotEmpty();
RuleFor(item => item.LastName).NotEmpty().When(item => !string.IsNullOrEmpty(item.FirstName))
}
}
We would like to have client side validation for this. I tried to create a custom FluentValidationPropertyValidator. But I can't find a way to pickup the When part of the validation rule. Can someone point me in right direction?