Verifying a Single Property Using the Fluent Validation Library for .Net

You can only check one property with Fluent Validation , and if so, how? I thought this discussion thread from January 2009 showed me how to do this using the following syntax:

validator.Validate(new Person(), x => x.Surname); 

Unfortunately, this does not work in the current version of the library. Another thing that made me think that testing a single property might be possible is the following quote from Jeremy Skiners post :

“Finally, I added the ability to be able to execute some of the Validation Property Validators without having to validate the entire object. This means that now you can stop the default“ Value was required ”message from being added to ModelState.

However, I don't know if this means that it only supports validation of a single property or the fact that you can tell the validation library to stop validation after the first validation error.

+6
validation asp.net-mvc fluentvalidation
source share
1 answer

According to this discussion on CodePlex, this ability is added through extension methods. You will need to import the FluentValidation namespace to display them in IntelliSense.

+4
source share

All Articles