Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

jquery - Fluent Validations. Error: Validation type names in unobtrusive client validation rules must be unique

I got the erorr:

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

I used server validation. And all worked fine. But now I`m stating to use client-side validation and I got this problem.

This is my validation class code:

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();          
        }
}

But if I leave one validator - all works fine. What should I do to have more that one validation for field.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This error is shown if you have the same validation on the same element more than once.

Not setting AddImplicitRequiredAttributeForValueTypes = false for both the default DataAnnontations and your FluentValidation will add a Required validation on any ValueTypes (like an int). If you at the same time add a RuleFor (or a [Required] attribute) on any ValueType you will have an extra Required for that field.

For that reason (I want to set all validations explicitly) I have the following in my Application_Start():

var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(new AttributedValidatorFactory());
ModelValidatorProviders.Providers.Add(fluentValidationModelValidatorProvider);
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
fluentValidationModelValidatorProvider.AddImplicitRequiredValidator = false;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...