我正在对我正在进行的项目进行客户端验证。一切正常,除了StringLength属性的minimumlength属性(它在提交和服务器端验证完成时有效):
[StringLength(50, MinimumLength = 6)]
Html.EnableClientValication();
生成的javascript如下:
// 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})
重要的是:
{"minimumLength":0,"maximumLength":50}
它使用错误的minimumproperty生成javascript。你们有提示吗?这可能是一个错误吗?
答案 0 :(得分:2)
这是来自反射器的代码
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) };
}
}
是的,这是一个非常不对的。