I'm trying to validate a generic list e.g List<Sales> so that the list should contain at least one item added via check boxes.
Here is how I've tried to work this:
public class SalesViewModel :IValidatableObject
{
[Required]
public List<Sales> AllSales{ get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (AllSales.Length == 0)
yield return new ValidationResult("Please pick one sales item");
}
}
Just want to know if this is the right approach to this kind of scenario.