0

I have a page that displays Companies, they all are appart of groups. Here is the display of the page: enter image description here

The first column contains the names of the groupes and the second of the companies.

What I want to achieve is to order the list first by Group name alphabetically (which has been done) and THEN order the items that are appart of one group alphabetically between each other.

I order the Groups like such :

 return View(_service.List().OrderBy(o => o.GroupId).ToList());

Where _service.List() gives the list of Groups.

How can I achieve it?

1 Answers1

3

You can use ThenBy method:

var model = _service.List()
    .OrderBy(o => o.GroupId)
    .ThenBy(x => x.Company)
    .ToList()
return View(model);
Zergling
  • 516
  • 2
  • 7
  • Lovely ! But can I even go crazy and do it twice? `_service.List() .OrderBy(o => o.GroupId) .ThenBy(x => x.Company).ThenBy(z => z.Name) .ToList()` because it doesn't seem to let me do it. EDIT: Of course I can, my error came from something else. Thank you ! –  Dec 21 '15 at 14:05