![](/img/trans.png)
[英]How would I validate string length using DataAnnotations in asp.net mvc?
[英]How can I validate a textbox input to be a positive or negative integer in mvc using dataannotations
用户可以输入正负浮点数。 目前我正在使用
[Range(0, double.MaxValue, ErrorMessage = "Only integers are allowed")]
但是当我输入以-开头的负数时,请给我验证错误。
将您的RangeAttribute
更改为
[Range(double.MaxMinValue, double.MaxValue, ErrorMessage = "Only integers are allowed")]
旁注:我认为错误消息应该是"Only numbers are.."
? 您允许的浮点数,不仅是整数,而且如果您将其应用到的属性是typeof double
,那么RangeAttribute
实际上不是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.