Try our conversational search powered by Generative AI!

How to randomly select/pick any random item from ContentArea in Episerver


I have added a number of blocks as contentArea Items in a ContentArea property.

I need to randomly pick a contentarea item and display it.

I don't want it in the order its mentioned in the contentarea

Please Help!!!

Jun 11, 2020 8:52

Pick a random content area item:

public virtual ContentArea ContentArea { get; set; }

public ContentAreaItem RandomItem
        var random = new Random();
        return ContentArea?.FilteredItems.OrderBy(x => random.Next()).FirstOrDefault();
Edited, Jun 11, 2020 9:13

An alternative approach would be to make a Random Visitor Group and then personalising the blocks in the content area.  

Jun 12, 2020 9:26

var random = new Random(unchecked((int)(DateTime.Now.Ticks)));
IList<ContentAreaItem> randomItemsList = contentAreaItemsList.OrderBy(t => random.Next(contentAreaItemsList.Count)).ToList();

Jun 12, 2020 9:35

I thought you wanted to pick one content area item randomly.

Your own answer, that you accepted as the answer, returns all items in random order.

Jun 12, 2020 9:38
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.