I have jquery validation(With twitter bootstrap) on my page and I use the following ASP.NET MVC annotation.
[DisplayName("Text)"),Range(100,35000)]
public decimal Field { get; set; }
The element is added with:
@Bootstrap.TextBoxFor(x => x.Field, htmlAttributes: new {@class="ignore",id="field" })
The problem is that I want to allow an empty value in this field but keep the range validation in case a non empty value in written.
This is my javascript code:
$("#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" });
I found the solution…If you make the type nullable it works…
Thank you for your help!