C# Order by in foreach

后端 未结 3 1588
死守一世寂寞
死守一世寂寞 2021-01-12 08:06

I\'m new to MVC C#.

Here is a ready and working code (the part of the working code).

@foreach (var item in Model)
{            
    
相关标签:
3条回答
  • 2021-01-12 08:32

    Directly use orderby

    @foreach (var item in Model.OrderBy(i => i.Order))
    {            
        <div style="height: 200px; ">
            @Html.Raw(@item.Description)
        </div>
    }
    
    0 讨论(0)
  • 2021-01-12 08:36

    You can use the Linq OrderBy extension method

    @foreach (var item in Model.OrderBy(i => i.Order))
    {
    }
    
    0 讨论(0)
  • 2021-01-12 08:42

    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>
    }
    
    0 讨论(0)
提交回复
热议问题