Data Annotations for validation, at least one required field?
问题 If I have a search object with a list of fields, can I, using the System.ComponentModel.DataAnnotations namespace, set it up to validate that at least one of the fields in the search is not null or empty? i.e All the fields are optional but at least one should always be entered. 回答1: I'd create a custom validator for this - it won't give you client side validation, just server side. Note that for this to work, you'll need to be using nullable types, as value types will default to 0 or false :