ASP.NET MVC的2 DataAnnotations StringLength [英] ASP.NET-MVC 2 DataAnnotations StringLength

查看:83
本文介绍了ASP.NET MVC的2 DataAnnotations StringLength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用MVC 2 DataAnnotations指定的字符串字段的最小长度?

Can I use the MVC 2 DataAnnotations to specify a minimum length for a string field?

有没有人这样做还是有他们创造自定义属性,如果是你不介意共享源?

Has anyone done this or have they created custom attributes and if so do you mind sharing the source?

推荐答案

如果您正在使用asp.net 4.0中,你可以使用StringLength属性来指定的最小长度。

If you're using asp.net 4.0, you can use the StringLength attribute to specify a minimum length.

例如:

[StringLength(50, MinimumLength=1)]
public string MyText { get; set; }

这篇关于ASP.NET MVC的2 DataAnnotations StringLength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆