开发者

ASP.NET client side validation with dataannotations - javascript minimumlength zero

开发者 https://www.devze.com 2022-12-28 02:39 出处:网络
I\'m doing client side validation on a project I\'m working on. Everything works, except for the minimumlength property of the StringLength attribute (it works when submitting and a serverside validat

I'm doing client side validation on a project I'm working on. Everything works, except for the minimumlength property of the StringLength attribute (it works when submitting and a serverside validation is done):

[StringLength(50, MinimumLength = 6)]

The javascript generated by Html.EnableClientValication(); is the following:

// snip 
{"FieldName":"User.Password","ReplaceValidationMessageContents":true,"ValidationMessageId":"User_Password_validationMessage","ValidationRules":[{"ErrorMessage":"The field Password must be a string with a minimum length of 6 and a maximum length of 50.","ValidationParameters":{"minimumLength":0,"maximumLength":50},"Valida开发者_开发问答tionType":"stringLength"}]}],"FormId":"form0","ReplaceValidationSummary":false})

The important thing is here:

{"minimumLength":0,"maximumLength":50}

It produces javascript with the wrong minimumproperty. You guys have a hint? Is this a possible bug?


this is the code from reflector

    public class StringLengthAttributeAdapter : DataAnnotationsModelValidator<StringLengthAttribute>
    {
        // Methods
        public StringLengthAttributeAdapter(ModelMetadata metadata, ControllerContext context, StringLengthAttribute attribute) : base(metadata, context, attribute)
        {
        }

        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
           return new ModelClientValidationStringLengthRule[] 
{ new ModelClientValidationStringLengthRule(base.ErrorMessage, 
-> 0 <-, base.Attribute.MaximumLength) };
        }
    }

yea, this is a quite not right.

0

精彩评论

暂无评论...
验证码 换一张
取 消