How to limit number of elements in ILIST

Vote:
 

I need to add only 4 elements in IList. How can I do that?

[CultureSpecific]
[Display(Name = "Items", GroupName = PropertyGroupNames.Content, Order = 20)]
[EditorDescriptor(EditorDescriptorType = typeof(AnswerListPropertyDescriptor))]

public virtual IList<AnswerBlock> Answers { get; set; }

I tried to use [MaxLength(4)] but its not working. Please help?

#223846
Jun 05, 2020 5:34
Vote:
 

I solved this issue by adding 

[ListItems(4)]

attribute.

[CultureSpecific]
[Display(Name = "Items", GroupName = PropertyGroupNames.Content, Order = 20)]
[EditorDescriptor(EditorDescriptorType = typeof(AnswerListPropertyDescriptor))]
[ListItems(4)]

public virtual IList<AnswerBlock> Answers { get; set; }

This works.

#223848
Jun 05, 2020 6:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.