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

New Post: FluentValidation does not honour ModelMetadata.IsRequired

$
0
0
I'm using a custom ModelMetadataProvider to help build a dynamic UI. One thing that it does is to set ModelMetadata.IsRequired based on whether the property is required or not.

With the default DataAnnotationsModelValidatorProvider in MVC 4 this enough to set up the necessary client side validation to ensure text is entered e.g.
<input class="input-mini valid" data-val="true" data-val-required="The Background Color field is required." id="Styles_bodyBackground_" name="Styles[bodyBackground]" type="text" value="#ffffff">
However, with the FluentValidationModelValidatorProvider enabled I no longer get the client side required validation.

Here is my initialization code:
            FluentValidationModelValidatorProvider.Configure(cfg =>
            {
                cfg.ValidatorFactory = new StructureMapValidatorFactory();
                cfg.AddImplicitRequiredValidator = false;
            }););
Most of my validation is done using attributes, I'm only using FluentValidation to perform complex validation as it works well with DI.

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>