Tuesday, 14 June 2016

c# - How do I order by lastname?





How do I order my list with people alphabetical? I have the people randomly in a list but I want it to be alpabetical ordered. How do I do that?



Here is my code:



@if (ViewBag.Roles.CanModify)
{



Sleep naar een groep om deze toe te voegen





}


Answer



You can use OrderBy for that:



@foreach (var LedenA in Model.Groepen.AllMembers.OrderBy(x => x.Anaam))
{ }



If you want to sort on the first name after that, use ThenBy:



@foreach (var LedenA in Model.Groepen.AllMembers.OrderBy(x => x.Anaam).ThenBy(x => x.Vnaam))
{ }

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...