vb.net - MVC Dataannotation validation rule for a collection? -


is there dataannotation validate rule collection based property?

i have following

  <displayname("category")>   <range(1, integer.maxvalue, errormessage:="please select category")>   property categoryid integer    <displayname("technical services")>   property technicalservices list(of integer) 

i'm looking validator can add technicalservices property set minimum collection size.

i think might help:

public class minimumcollectionsizeattribute : validationattribute {     private int _minsize;     public minimumcollectionsizeattribute(int minsize)     {         _minsize = minsize;     }      public override bool isvalid(object value)     {         if (value == null) return true;         var list = value icollection;          if (list == null) return true;          return list.count >= _minsize;     }     } 

there's room improvement, that's working start.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -