I have an MVC3 project for which I use NinjectMVC3 for dependency injection - so far everything works great. Recently, I wanted to localize all the texts in the application and from all the options I have seen the one presented here seems to be the cleanest. If not used in the same time with the default NinjectMVC3 setup, this solution is the perfect fit.

However, when NinjectMVC3 is added to the project the following error (and the YSOD) is displayed for any property decorated with the [Required] attribute: Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required

Based on the error it looks like there are 2 or more Validator Providers registered with ModelValidatorProvidersCollection.

Note: in web.config the following settings exist for client side unobtrusive validation and I want to keep them this way:

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

Does anybody have any idea how to overcome this?

有帮助吗?

解决方案

The author of the original solution mentioned that NinjectMVC overrides any ModelValidatorProviders definitions set in global.asax. There might be some way to overcome the situation, but it seems to be quite complex.

Another option that I found is FluentValidation for which Ninject team created an extension:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top