例如,我有 2 个项目: Item1 是string
, Item2 是int
。如何为 Item1 8 个字符和 Item2 5 个数字(在 c# 中)设置最大长度?
问问题
1284 次
1 回答
0
为此,只需使用StringLengthAttribute和IntegerValidatorAttribute。
class TestCase
{
[StringLength(8, ErrorMessage = "The TestString value cannot exceed 8 characters.")]
[Required(ErrorMessage="Value Required")]
property string TestString;
[IntegerValidator(MaxValue = 99999)]
property int TestInt;
}
于 2013-03-04T13:10:40.777 回答