Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Ninject from overriding custom DataAnnotationsModelValidatorProvider?

I have a custom DataAnnotationsModelValidatorProvider for doing model validation in a more dynamic way then just adding attributes. I tried to add my provide to the global.asax.cs like so:

ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new AttributeValidatorProvider());

But once I load my form, I get an error saying "Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required".

According to a comment on this blog, this is because Ninject is overriding custom validator providers.

I'm fairly new to MVC and I can't seem to find a way to tell Ninject to accept my custom providers as well, how would I go about fixing this problem?

For the record: I do not wish to use Fluentvalidation.net, I want to stick with the default MVC validations (for the most part).

like image 534
sebastiaan Avatar asked Dec 02 '11 13:12

sebastiaan


1 Answers

Change the registration of the provider to

Rebind<ModelValidatorProvider>().To<AttributeValidatorProvider>();
like image 119
Remo Gloor Avatar answered Sep 19 '22 00:09

Remo Gloor