本文介绍了MVC3 jQuery验证过滤MINLENGTH不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这在我的方式:

[Required(AllowEmptyStrings = false, ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "NameRequired")]
[MinLength(3, ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "NameTooShort")]
public String Name { get; set; }

这在结束了:

    <div class="editor-label">
        <label for="Name">Name</label>
    </div>
    <div class="editor-field">
        <input class="text-box single-line" data-val="true" data-val-required="Name is required" id="Name" name="Name" type="text" value="" />
        <span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"></span>
    </div>

怎么会是MINLENGTH被编译器忽略?我怎样才能打开它?

How come MinLength is being ignored by the compiler? How can I "turn it on"?

推荐答案

而不是使用<$c$c>MinLength属性用这个代替:

Instead of using MinLength attribute use this instead:

[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]

String长度MSDN

优点:不需要编写自定义属性

Advantage: no need to write custom attribute

这篇关于MVC3 jQuery验证过滤MINLENGTH不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 20:20