Matthew H
Matthew H

Reputation: 5879

ASP.NET MVC 2 Data Annotation Validation -- StringLength Minimum not working on client-side

On one of my models I have a property annotated with:

[StringLength(60, ErrorMessage="Title must be between 60 and 10 characters", MinimumLength=10)]

When the form posts to the server, if it's under 10 characters, then validation fails as it should do. However, on the client-side, it only checks that it's under 60 characters -- not also above 10 characters.

Here's the JSON, note that the minimum length is 0:

<![CDATA[if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }window.mvcClientValidationMetadata.push({"Fields":[{"FieldName":"Title","ReplaceValidationMessageContents":true,"ValidationMessageId":"Title_validationMessage","ValidationRules":[{"ErrorMessage":"Title must be between 60 and 10 characters","ValidationParameters":{"minimumLength":0,"maximumLength":60},"ValidationType":"stringLength"}]};//]]>

Upvotes: 2

Views: 5064

Answers (1)

Buildstarted
Buildstarted

Reputation: 26689

It appears to be a bug in MVC 2 that was fixed in MVC 3

Upvotes: 4

Related Questions