1

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},"ValidationType":"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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi! Thanks for verifying this as a bug. Where did you find the source? I've looked aspnet.codeplex.com, but didn't find it.
Good old Reflector - free tool to disassemble code from .net dll. Very useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.