Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Dependent Validations

$
0
0

Hi

Your method declaration doesn't look quite right. There are two overloads for Must - one accepts the property value, the other accepts the instance being validated and the property value. In your example, neither of these are being used. I'd suggest taking a look at the documentation for Must: 

http://fluentvalidation.codeplex.com/wikipage?title=Validators&referringTitle=Documentation&ANCHOR#Predicate

Here's a modified version that should compile:

RuleFor(customer => customer.HomeCountry).NotEmpty().Must(IsValidCountryCategory).WithMessage("Select a valid country");

private bool IsValidCountryCategory(Customer customer, string homeCountry)
{
   // From here you can now access properties of the Customer directly
}

 


Viewing all articles
Browse latest Browse all 1917

Trending Articles