API Reference: MinCountAttribute Class

The MinCountAttribute can be applied to collection-based content model properties. The attribute sets the minimum number of items that must be added to the property value in the back office application. The back office will display a validation error if the minimum is not reached.

You can combine this attribute with the MaxCount attribute to specify a min/max range.

Usage

Decorate the model property with the MinCountAttribute. Pass the minimum required number of items in the attribute constructor.

The attribute can only be applied to collection-based properties (i.e. IList<T>, ICollection<T>, etc.). An exception will be thrown if the attribute is applied to a non-collection-based property.

Example

The following example specifies a minimum count of 2 items for the PageLinks property (as well as a maximum count of 5).

public class SampleContent: IContentType
{
    [MinCount(2)]
    [MaxCount(5)]
    public IReadOnlyList<Link> PageLinks { get; set; }

    // ...
}