C# Order by in foreach

asp.net-mvc, c#

Solution

Use OrderBy extension method on IEnumerable in System.Linq namespace

@foreach (var item in Model.OrderBy(i => i.Order))
{            
    <div style="height: 200px; ">
        @Html.Raw(@item.Description)
    </div>
}

Problem

I'm new to MVC C#. Here is a ready and working code (the part of the working code). ``` @foreach (var item in Model) { <div style="height: 200px; "> @Html.Raw(@item.Description) </div> } ``` The problem is the Description is not displayed on the page in the proper order is. So, the order of `<div>`s should be slightly different. How to modify the code so it works properly? The order of the `Description` field should be ordered by `Order` column.

Original source