我收到错误:
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required. The following validation type was seen more than once: required
我使用了服务器验证。一切都很好。 但现在我声明使用客户端验证,但遇到了这个问题。
这是我的验证类代码:
public class TestViewDataValidation : BaseTestCreateViewDataValidation<BaseTestCreateViewData>
{
public TestViewDataValidation ()
{
this.RuleFor(x => x.Login).NotNull();
this.RuleFor(x => x.Login).NotEmpty();
this.RuleFor(x => x.Login).EmailAddress();
}
}
但是如果我留下一个验证器 - 一切都会正常。 我应该做什么才能对字段进行不止一次验证。
最佳答案
如果您对同一元素多次进行相同的验证,则会显示此错误。
不为默认 DataAnnontations 设置 AddImplicitRequiredAttributeForValueTypes = false
和,您的 FluentValidation 将为任何 ValueType(如 int
)添加必需的验证。如果您同时在任何 ValueType 上添加 RuleFor(或 [Required]
属性),您将为该字段添加一个额外的 required。
出于这个原因(我想显式设置所有验证),我的 Application_Start()
中有以下内容:
var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(new AttributedValidatorFactory());
ModelValidatorProviders.Providers.Add(fluentValidationModelValidatorProvider);
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
fluentValidationModelValidatorProvider.AddImplicitRequiredValidator = false;
关于jquery - 流畅的验证。错误: Validation type names in unobtrusive client validation rules must be unique,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4767457/