码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET MVC中MaxLength特性设置无效

时间:2014-11-28 14:02:59      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:style   ar   color   os   使用   sp   on   bs   html   

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

ASP.NET MVC中MaxLength特性设置无效

标签:style   ar   color   os   使用   sp   on   bs   html   

原文地址:http://www.cnblogs.com/darrenji/p/4128169.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!