DataAnnotation Range 属性上的客户端验证行程 [英] client-side validation trips on DataAnnotation Range attribute

查看:18
本文介绍了DataAnnotation Range 属性上的客户端验证行程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型类中有以下代码:

I have the following code in my Model class:

    [Range(1, 100)]
    public decimal Price { get; set; }

最近将 jquery.validate 升级(我假设)到 1.11.0 后,即使我输入了有效值,我也会收到错误消息.如果我在 web.config 中关闭客户端验证 - 工作正常.所有其他属性(StringLength、Required)都可以正常工作.生成的 HTML 如下(为清晰起见添加了换行符):

After recent upgrade (I assume) of jquery.validate to 1.11.0, I am getting an error even if I enter valid value. If I turn off client validation in web.config - works fine. All other attributes (StringLength, Required) work fine. Generated HTML is the following (line breaks added for clarity):

<input class="text-box single-line" data-val="true" 
data-val-number="The field Price must be a number." 
data-val-range="The field Price must be between 1 and 100." 
data-val-range-max="100" data-val-range-min="1" 
data-val-required="The Price field is required." id="Price" name="Price" 
type="text" value="" />

我很确定它以前有效......除了 jquery.validate 中的错误之外,想不出任何其他的东西.

I am pretty sure it worked before... Can't think of anything but the bug in jquery.validate.

推荐答案

Microsoft 发布了对 microsoft.jQuery.Unobtrusive.Ajax 和 microsoft.jQuery.Unobtrusive.Validation 的更新(从版本2.0.20710.0"到2.0.0").30116.0') 解决了.live 和验证问题

Microsoft issued an update to microsoft.jQuery.Unobtrusive.Ajax and to microsoft.jQuery.Unobtrusive.Validation (from version '2.0.20710.0' to '2.0.30116.0') that fixes both .live and validation problems

这篇关于DataAnnotation Range 属性上的客户端验证行程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆