Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Ordering a list within an ordered list

$
0
0

Hello.

I have a model (Generic Model) that has an IList of another model (Unit).  Within in that model there is an IList of a different model (Section).

When I pull some information I want to sort the Unit list by UnitNumber and then within each Unit sort the Section list by SectionNumber.  I can get it to work in a round about way, but I was wondering if there was an easier way to do it.  

How I do it now is create a new Section Object, manipulate it then set it to the Unit.

This is how I would like to do it (or something similar):

viewModel.Units = viewModel.Units.OrderBy(x => x.UnitNumber).ToList();
foreach(var u in viewModel.Units)
{
     u.Sections.OrderBy(s => s.SectionNumber).ToList();
}

The above works for the Units, but not the Sections.

Any thoughts?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>