开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜