#6 Basic sorting of lists
Simple Sorting of Persons
OrderBy(EntityId)
This example shows A-Z ordering by a property which exists on all entities: EntityId
- Douglas Adams (#5920)
- Terry Pratchett (#5921)
- Neil Gaiman (#5922)
- George Akerlof (#5926)
- Raphael Müller (not an author) (#5930)
- Ed Hardy (#5931)
<ol>
@foreach(var person in persons.OrderBy(p => p.EntityId)) {
<li>@person.FirstName @person.LastName (#@person.EntityId)</li>
}
</ol>
OrderBy(FirstName)
This example shows A-Z ordering by a property which exists only on Person-entities. This is simple with dynamic
objects
- Douglas Adams
- Ed Hardy
- George Akerlof
- Neil Gaiman
- Raphael Müller (not an author)
- Terry Pratchett
<ol>
@foreach(var person in persons.OrderBy(p => p.FirstName)) {
<li>@person.FirstName @person.LastName</li>
}
</ol>
OrderByDescending(Birthday)
This example shows Z-A ordering by a property.
- Raphael Müller (not an author) (3/1/2000)
- Neil Gaiman (11/10/1960)
- Douglas Adams (3/11/1952)
- Terry Pratchett (4/28/1948)
- Ed Hardy (1/1/1945)
- George Akerlof (6/17/1940)
<ol>
@foreach(var person in persons.OrderByDescending(p => p.Birthday)) {
<li>@person.FirstName @person.LastName (@person.Birthday.ToString("d"))</li>
}
</ol>
#6 Basic sorting of lists
@inherits Custom.Hybrid.Razor14
@using System.Linq;
<!-- unimportant stuff, hidden -->
@{
var persons = AsList(App.Data["Persons"]);
}
@Html.Partial("_header.cshtml")
<div class="row">
<div class="col-lg-7">
<h2>Simple Sorting of Persons</h2>
<h3>OrderBy(EntityId)</h3>
</div>
@Html.Partial("../shared/_DefaultInfoSection.cshtml")
</div>
<p>This example shows A-Z ordering by a property which exists on all entities: EntityId</p>
<ol>
@foreach(var person in persons.OrderBy(p => p.EntityId)) {
<li>@person.FirstName @person.LastName (#@person.EntityId)</li>
}
</ol>
<hr>
<h3>OrderBy(FirstName)</h3>
<p>This example shows A-Z ordering by a property which exists only on Person-entities. This is simple with <code>dynamic</code> objects</p>
<ol>
@foreach(var person in persons.OrderBy(p => p.FirstName)) {
<li>@person.FirstName @person.LastName</li>
}
</ol>
<hr>
<h3>OrderByDescending(Birthday)</h3>
<p>This example shows Z-A ordering by a property.</p>
<ol>
@foreach(var person in persons.OrderByDescending(p => p.Birthday)) {
<li>@person.FirstName @person.LastName (@person.Birthday.ToString("d"))</li>
}
</ol>
<!-- unimportant stuff, hidden -->