开发者

How do I add an order by to server side code in my mvc View

开发者 https://www.devze.com 2022-12-13 20:48 出处:网络
How can I append to the first line .OrderBy and specify a property OrderById. I\'m finding it confusing, i.e. Func & KeySelector etc.

How can I append to the first line .OrderBy and specify a property OrderById. I'm finding it confusing, i.e. Func & KeySelector etc.

<% foreach (var item in Model.PaymentItemTotals)
{ %>
    <tr>
        <td><%= Html.Encode(item.Line)%></td>
        <td><strong><%= String.Format("{0:C}", item.AmountTotal)%></strong></td>
        <td><%= String.Format("{0:C}", item.Amount)%>&开发者_运维知识库lt;/td>
        <td><%= String.Format("{0:C}", item.AmountIndex)%></td>
    </tr>                    
 <% } %>


foreach (var item in Model.PaymentItemTotals
    .OrderBy(paymentItemTotal => paymentItemTotal.OrderById))

But consider doing this ordering either in your Model or Controller to make your view as stupid as possible.


 collection.OrderBy(o => o.FieldToOrderBy)

You may order on the controller before you pass it to the view.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号