How to randomise and limit the number of items in a foreach loop
Hi all,
Please forgive my ignorance as I am very new to Umbraco (3 months) and I am still learning C#.
I have created a Partial View Macro to display items on the front end of my site however I do not know how to get a random item from the foreach loop whilst also limiting it to 1 item.
I have attached my Partial View Macro File code for you to view below.
How to randomise and limit the number of items in a foreach loop
Hi all,
Please forgive my ignorance as I am very new to Umbraco (3 months) and I am still learning C#.
I have created a Partial View Macro to display items on the front end of my site however I do not know how to get a random item from the foreach loop whilst also limiting it to 1 item.
I have attached my Partial View Macro File code for you to view below.
Thanks,
Don
Hi Don
Try this code:
You can get random item with this code -
And you don't need a loop then.
Alex
Thanks you for your help. Really appreciate it.
is working on a reply...