ASP.NET-MVC 2 DataAnnotations StringLength

前端 未结 2 661
感情败类
感情败类 2021-02-02 08:47

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 sha

2条回答
  •  野的像风
    2021-02-02 08:56

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

    Eg:

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

提交回复
热议问题