1

I have a User object that has a collection of Items.

How can I randomize the Items so they dont' appear in the exact same order everytime.

I'm currently ordering by SortOrder (integer), but this will obviously be in the same order everytime.

@foreach(UserItems ui in Model.User.Items.OrderBy(x => x.SortOrder))
{

}
loyalflow
  • 14,275
  • 27
  • 107
  • 168

1 Answers1

3

Here's a little trick:

@foreach(UserItems ui in Model.User.Items.OrderBy(x => Guid.NewGuid()))
{

}
Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156