在ASP.NET MVC项目中,给某个Model打上了MaxLength
特性如下:
public class SomeClass{[MaxLength(16, ErrorMessage = "最大长度16")]
public string SomeProperty{get;set;}}
但在其对应的表单元素中并没有出现类似data-val-length
属性。
解决办法:使用StringLength
替代MaxLength
。
public class SomeClass{[StringLength(16, ErrorMessage = "最大长度16")]
public string SomeProperty{get;set;}}