FluentValidation is not called

I have an MVC 3 site, but I'm using a non-MVC FluentValidation dll. I created a validator class and placed all my RuleFors in the constructor, and then set the attribute in my model class, thereby

[FluentValidation.Attributes.Validator(typeof(MyValidator))] 

The problem is that the validator class constructor is never called. I think this may be because I am not using the MVC DLL version, but then I could not get this version to work for me either.

Any help would be appreciated.

Thanks,

Sechin

+4
source share
1 answer

In Application_Start make sure you initialize the user version of the authentication model authentication model, otherwise nothing will happen:

 FluentValidation.Mvc.FluentValidationModelValidatorProvider.Configure(); 

The FluentValidationModelValidatorProvider class FluentValidationModelValidatorProvider defined inside the FluentValidation.Mvc assembly. Please see the documentation for integrating FluentValidation into an ASP.NET MVC site .

The validator will be activated when the controller action is called with a model decorated with the [Validator] attribute as an argument:

 [HttpPost] public ActionResult Process(MyViewModel model) { ... } 
+6
source

All Articles