数据注释中的范围属性问题

时间:2017-02-06 06:03:23

标签: c# regex

我正在使用Web APi,我将Range属性放在双可空字段上。这是表达式。

[Range(0, 6,ErrorMessage = "Value for {0} must be between {1} and {2}.")]
        public Nullable<double> int_term { get; set; }

但是当我测试它只接受一个数字即。 1或2到6等。如果我把12然后它通过错误。

"Value for int_term_depth_eng must be between 0 and 6."

允许最多6位数或+/- 5位

的表达式

1 个答案:

答案 0 :(得分:1)

Range attribute指示可以作为输入允许的数值范围。因此它只允许0到6之间。

如果您希望它允许6位数字,那么您需要将其设为

[Range(-99999, 999999, ErrorMessage = "Value for {0} must be between {1} and {2}.")]
相关问题