My controller passes the list of objects to my view, allowing me to:
@foreach (var optiongroup in Model) {
Inside the model is an IEnumerable<Option> . I need to sort this parameter list so that with I:
@foreach (var option in optiongroup.Options){
As a result, I get a list in which the elements are sorted by the option.SortOrder property instead of the ordinal position of each element.
So how do I get a list sorted before foreach ? I tried:
@foreach (var option in optiongroup.Options.OrderByDescending(o => optiongroup.SortOrder))
and
IEnumerable<Option> allOptions = optiongroup.Options.OrderByDescending(o => optiongroup.SortOrder);
but have not yet reached joy.
THX
source share