I am trying to sort my list in alphabetical order before viewing all the details on my page.
This is my code to get a clearer image of what I'm trying to say:
<div id= "teamMain" style="margin-left: 45px";>
<% foreach (var item in Model.getTeams) { %>
<a href="Statistics?id=<%: encrypted %>" class="teamImage">
<img src="../../<%: item.image %>" alt="<%: item.name %>" />
</a>
<% } %>
</div>
I need to sort my list in alphabetical order before showing it.
Thanks.
In your model you can use OrderBy
.
For instance:
public IEnumerable<Teams> getTeams
{
get { return _teams.OrderBy(t => t.Name); }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With