I have the following class:
public class CreateJob
{
[Required]
public int JobTypeId { get; set; }
public string RequestedBy { get; set; }
public JobTask[] TaskDescriptions { get; set; }
}
I’d like to have a data annotation above TaskDescriptions so that the array must contain at least one element? Much like [Required]. Is this possible?
I’ve seen a custom validation attribute used for this before, like this:
(I’ve given sample with a list but could be adapted for array or you could use list)
Credit to Antonio Falcão Jr. for elegance