tationsModelValidatorProvider停止N

tationsModelValidatorProvider停止N

本文介绍了如何从覆盖定制DataAnnotationsModelValidatorProvider停止Ninject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更动态的方式然后只添加属性做模型验证定制DataAnnotationsModelValidatorProvider。我试图加我提供像这样的global.asax.cs:

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".

据在这个博客上评论,这是因为Ninject是压倒一切的自定义验证提供商。

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

我是相当新的MVC和我似乎无法找到一种方法来告诉Ninject接受我的自定义提供商,以及,我将如何去解决这个问题?

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?

有关记录:我不希望使用Fluentvalidation.net,我想用默认的MVC验证坚持(大部分)

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

推荐答案

供应商登记更改为

Rebind<ModelValidatorProvider>().To<AttributeValidatorProvider>();

这篇关于如何从覆盖定制DataAnnotationsModelValidatorProvider停止Ninject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:30