在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;}
}

相关文章:

  • 2022-12-23
  • 2022-01-13
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-02-03
相关资源
相似解决方案