I'd like to make 2 rules using Fluent Validation (http://fluentvalidation.codeplex.com) in my MVC project.
Nothing should happen when both Company and Name are empty. If either of them is filled, nothing should happen either. If either Company or Name is not filled, display a label at both of them. (the error message could be the same)
Ive tried this so far:
RuleFor(x => x.Name)
.NotEmpty()
.WithMessage("Please fill in the company name or the customer name")
.Unless(x => !string.IsNullOrWhiteSpace(x.Company));
RuleFor(x => x.Company)
.NotEmpty()
.WithMessage("Please fill in the company name or the customer name")
.Unless(x => !string.IsNullOrWhiteSpace(x.Name));
Ive tried combinations of When, Must and Unless, but none of them work. When i fill in nothing, no errors are shown on those 2 properties.
Can anyone help me out?