Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I need to pull x random items from nested content. If i were to do it on nodes i would do:
@foreach(var t in Umbraco.Content(1056).Children().Random(2)) { <p>@t.Name</p> }
Which works fine. In nested content context i tried doing:
@{ var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("sponsorer"); foreach(var item in items.Random(2)) { <p>@item.GetPropertyValue("name")</p> } }
but them i get an error "CS1061: 'System.Collections.Generic.IEnumerable
Hi Claushingebjerg
This code should work for you:
foreach(var item in items.OrderBy(n => Guid.NewGuid()).Take(2))
Hope it will help.
Alex
you can use this one
items.RandomOrder();
Exactly, thanks Yakov, it's definitely the best method.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Getting random items
I need to pull x random items from nested content. If i were to do it on nodes i would do:
Which works fine. In nested content context i tried doing:
but them i get an error "CS1061: 'System.Collections.Generic.IEnumerable
Hi Claushingebjerg
This code should work for you:
Hope it will help.
Alex
you can use this one
Exactly, thanks Yakov, it's definitely the best method.
is working on a reply...