Validate a single property with the Fluent Validation Library for .Net

Posted by Blegger on Stack Overflow See other posts from Stack Overflow or by Blegger
Published on 2010-05-17T15:11:46Z Indexed on 2010/05/17 15:30 UTC
Read the original article Hit count: 471

Can you validate just a single property with the Fluent Validation Library, and if so how? I thought this discussion thread from January of 2009 showed me how to do it via the following syntax:

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

Unfortunately it doesn't appear this works in the current version of the library. One other thing that led me to believe that validating a single property might be possible is the following quote from Jeremy Skinners' blog post:

"Finally, I added the ability to be able to execute some of FluentValidation’s Property Validators without needing to validate the entire object. This means it is now possible to stop the default “A value was required” message from being added to ModelState. "

However I do not know if that necessarily means it supports just validating a single property or the fact that you can tell the validation library to stop validating after the first validation error.

© Stack Overflow or respective owner

Related posts about fluent-validation

Related posts about ASP.NET