4

例如,我有 2 个项目: Item1 是string, Item2 是int。如何为 Item1 8 个字符和 Item2 5 个数字(在 c# 中)设置最大长度?

4

1 回答 1

0

为此,只需使用StringLengthAttributeIntegerValidatorAttribute

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 回答