我的页面上有 jquery 验证(使用 twitter 引导),我使用以下 ASP.NET MVC 注释。
[DisplayName("Text)"),Range(100,35000)]
public decimal Field { get; set; }
该元素添加有:
@Bootstrap.TextBoxFor(x => x.Field, htmlAttributes: new {@class="ignore",id="field" })
问题是我想在该字段中允许一个空值,但保留范围验证以防写入非空值。
这是我的 JavaScript 代码:
$("#Field").on("keyup", function (e) {
e.preventDefault();
if ($(this).val() == "") {
$(this).removeClass("input-validation-error");
$(this).addClass("valid");
$(this).next().html("");
$(this).parent().parent().removeClass("error");
}
})
$.validator.setDefaults({ ignore: ".ignore" });