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
Post a Comment