寻呼与放大器;排序电网与ASP.Net MVC [英] Paging & Sorting grids with ASP.Net MVC

查看:135
本文介绍了寻呼与放大器;排序电网与ASP.Net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MVC,和我不遵守你会怎么做分页和网格排序。我已经习惯了使用asp.Net GridView控件使用一个ObjectDataSource指着我们的业务层对象 - 在这种情况下,ODS处理所有分页和放大器;使用我们的ORM生成的对象的方法排序。

我看用与MVC相同的ORM - 和工作的事情在那里很好 - 我只是环通集合构建页的表格 - 但没有消耗臭氧层物质处理分页和放大器;排序,我很困惑,我会如何处理。我会为分页和排序一个单独的控制器?

我知道我需要推出自己的 - 但我从哪里开始?我创建了一个CustomerController,以及显示客户的表看起来像下方的观点 - 我要作为排序依据名字或姓氏列。我的模型上有说会采取一个字符串排序的前pression在将由一个GridView / ODS成对使用的格式sort()方法。我会创造我的CustomerController称为排序一个新的动作,并把一个ActionLink的在我的头?

 <表>
    &所述; TR>
        <第i个
            名字
        < /第i
        <第i个
            姓
        < /第i
    < / TR>
    <%的foreach(在型号VAR项)
       {%GT;
    &所述; TR>
        &所述; TD>
            <%= Html.En code(item.FirstName)%GT;
        < / TD>
        &所述; TD>
            <%= Html.En code(item.LastName)%GT;
        < / TD>
    < / TR>
    <%}%GT;
< /表>


解决方案

您可以使用相同的控制器,只需添加一个额外的参数和排序命名。然后,在价值排序都有哪些控制器检查,并根据该参数的数据进行排序。

或者,如果你想要做在客户端的东西,你可以使用像的tablesorter ,jQuery的一个插件。

I'm new to MVC, and am not following how you'd do paging and sorting on a grid. I'm used to using the asp.Net GridView control with an ObjectDataSource pointed at objects in our business layer - and in that case the ODS handles all of the paging & sorting using the methods that our ORM generates on the objects.

I've looked at using the same ORM with MVC - and things work out fine there - i just loop thru the collections to build the table on the page - but without the ODS to handle the paging & sorting, i'm confused as to how I'd handle that. Would I have a separate controller for the paging and sorting?

I understand that I need to roll my own - but where do I start? I've created a CustomerController, and a view that displays a table of customers that looks like below - and I want to sort on FirstName or LastName columns. My Model has a Sort() method on it that'll take a string sort expression in the format that would be used by a GridView/ODS pair. Would I create a new Action on my CustomerController called Sort, and put an ActionLink in my header?

    <table>
    <tr>
        <th>
            First Name
        </th>
        <th>
            Last Name
        </th>
    </tr>
    <% foreach (var item in Model)
       { %>
    <tr>
        <td>
            <%= Html.Encode(item.FirstName) %>
        </td>
        <td>
            <%= Html.Encode(item.LastName) %>
        </td>
    </tr>
    <% } %>
</table>

解决方案

Your can use the same controller, just add an additional parameter and name it sort. Then check in the controller what value sort has, and sort your data based on that parameter.

Or if you want to do things on the client side, you can use something like tablesorter, a plugin for jquery.

这篇关于寻呼与放大器;排序电网与ASP.Net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆