views:

113

answers:

3

Hi!

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?

+2  A: 

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.

er-v
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.
Kordonme
Good old Reflector - free tool to disassemble code from .net dll. Very useful.
er-v
A: 

I think I'm reproducing this with the release version of VS 2010. Does anyone know if there is a fix for this, and when it will be "released"?

Jon
"release version of VS 2010" - i.e. the version of MVC 2.0 shipping with VS 2010
Jon
A: 

wait... it's 6/6/2010 and I'm using the release version of VS2010 and this problem still persisits... am I missing something???

My MVC DLL is @ C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll

JayRu
No, this is still a problem. I'm using the latest version of Visual Studio and the MVC framework.
Kordonme