对于非数值可空INT验证没有显示消息 [英] Nullable int validation not showing message for non-numeric values
问题描述
我使用jQuery验证,我有以下的HTML:
I'm using jQuery validation, and I have the following html:
<input data-val="true" data-val-number="The field Weight must be a number." data-val-range="The field Weight must be between 1 and 750." data-val-range-max="999" data-val-range-min="0" id="Weight" name="Weight" type="number" value="" />
<span data-valmsg-for="Weight" data-valmsg-replace="true"></span>
这是对我的模型属性的样子
This is how the property on my model looks like
[Range(1, 750)]
public int? Weight { get; set; }
当我使用范围0..999以外的号码,验证失败,我看到正确的消息。然而,当我使用非数字值,如 ABC
,表单通过验证。我在做什么错在这里?
When I use a number outside of the range 0..999, the validation fails, and I see the correct message. However, when I use a non-numeric value, such as abc
, the form passes validation. What am I doing wrong here?
这可能是值得指出的是,使用翻番?
工作得很好。同样的模式也有一个可为空的双重属性,还装饰有一个范围
属性。此特性使完全相同的HTML,除了 ID
和名称
。
It might be worth noting that using a double?
works just fine. The same model also has a nullable double property, also decorated with a Range
attribute. This property renders exactly the same html, except for the id
and name
.
推荐答案
修改键入=号
到键入=文字
解决我的问题。
这篇关于对于非数值可空INT验证没有显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!