c# - MVC3 范围属性 - 不允许值为零

标签 c# attributes

我的字段有以下属性:

[Range(-1,200)]
public decimal MyValue{ get; set; }

如果我输入任何不在我得到的范围内的值:

The field must be between -1 and 200

这很好。

这就是问题所在,当我输入有效值零时,我收到“字段必须是数字”验证消息。

有什么建议吗?
谢谢

最佳答案

我认为这可能是由于 decimal 类型造成的。试试这个:

[Range(typeof(Decimal),"-1", "200")]
public decimal MyValue{ get; set; }

Source.

关于c# - MVC3 范围属性 - 不允许值为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18020465/

相关文章:

c# - 数据集到 xml 空值

c# - 复制引用而不是新的深拷贝

javascript - 未捕获的类型错误 : Cannot read property 'player' of undefined

c# - 您可以访问特定枚举值的详细说明吗

xml - 是否可以在 Odoo 中的字段上实现条件属性?

c# - ATL 进程外回调接口(interface)上的“接口(interface)未注册”错误

c# - 如何将 Blazor 包含到现有项目中?

c# - C# 中字符串的行为

javascript - polymer 数据与 Javascript 和属性的绑定(bind)

特定类的 C# AttributeUsage