As a developer I find the requirement for custom validation comes up a lot. Clients don't always like the validation that .NET MVC throws out by default; sometimes clients want validation added to field-types that MVC doesn't directly support or they might want to add further checks to the conditions surrounding a specific message displaying.

All of these are perfectly reasonable requests.

Traditionally this has been pretty simple to achieve on the front-end using JavaScript validation but .NET makes it slightly trickier to add complex checks at a model level. In order to add validation to boolean values, for example, you would usually have to create a custom validation method for that purpose.

Expressive Annotations, built by Jaroslaw Waliszko, introduces the ability to add very simple annotation-based conditional validation to your models! Say goodbye to writing your own validation in the future, this library has you covered...

Expressive Annotations

To add custom validation to a field you simply add the "RequiredIf" (for conditionally setting a field to be required) or the "AssertThat" (for checking statements are true/false) annotations to the necessary fields in your model along with the conditions you want it set against and you're done.

Naturally you are also able to add your own custom error messages, or pull them from resource files, by adding the ErrorMessage properties to your annotations.

For more detail and a wider look at the posibilities this library can offer, there's documentation on the Github page for the project: https://github.com/JaroslawWaliszko/ExpressiveAnnotations

You can add this into your projects right now - it's installable as a handy nuget package:

Install-Package ExpressiveAnnotations

Or as a standalone DLL:

Install-Package ExpressiveAnnotations-DLL