I want to make 2 rules using Fluent Validation (http://fluentvalidation.codeplex.com) in my MVC project.
Nothing should happen when both companies and name are empty. If any of them are full, nothing should happen. If neither the company nor the name is empty, display a label on them. (error message may be the same)
I have 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 to combine When, Must and Unless, but none of them work. When I fill nothing, errors are not displayed on these 2 properties.
Can anyone help me out?
Robin source share