My controller passes a list of objects to my view allowing me to:
@foreach (var optiongroup in Model)
{
Within the Model is an IEnumerable<Option>. I need to sort this list of options such that when I:
@foreach (var option in optiongroup.Options){
I end up with a list where items are sorted on the property called option.SortOrder instead of the ordinal position of each item.
So how do I get a list sorted prior to the foreach? I’ve tried:
@foreach (var option in optiongroup.Options.OrderByDescending(o => optiongroup.SortOrder))
and:
IEnumerable<Option> allOptions = optiongroup.Options.OrderByDescending(o => optiongroup.SortOrder);
// then foreaching the allOptions list
but have yet to achieve joy.
thx
This
should be