API Reference: MaxCountAttribute Class

The MaxCountAttribute can be applied to collection-based content model properties. The attribute sets the maximum number of items that can be added to the property value in the back office application.

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

Usage

Decorate the model property with the MaxCountAttribute. Pass the maximum allowed 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 maximum count of 5 items for the PageLinks property (as well as a minimum count of 2).

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

    // ...
}