Try our conversational search powered by Generative AI!

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
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.