MVC 分页1 标准的url分页

一. 将mvcpager ddl 引用到web服务项目中.

二.

在view加入

<%@ Import Namespace="Webdiyer.WebControls.Mvc" %>

 

@Page 的Inherits属性改为

Inherits="System.Web.Mvc.ViewPage<PagedList<SuppliersInfo>>"

 

 

控制器那边 定义action 如:

public ActionResult List(int? id)
        { 
             IList<SuppliersInfo> suppliersList = Suppliers.Instance.GetSupplierList(); //返回列表
            PagedList<SuppliersInfo> orders = new PagedList<SuppliersInfo>(suppliersList,id?? 1,1); //定义分页
                return View(orders);            
        }

 

响应的视图那边: (示例)

            

<% if (Model.Count > 0)
               { %>
                <% foreach (SuppliersInfo suppliers in Model) //Model是mvcpager中的一个属性, 具体看vs那边的注释
                   { %>
                  <tr> 
                    <td><% = suppliers.SupplierId.ToString()%></td>
                    <td><% = suppliers.SupplierNo.ToString()%></td>
                    <td><% = suppliers.SupplierName.ToString()%></td>   
                    <td><% = suppliers.Intro.ToString()%></td>
                    <td><% = suppliers.Contactor.ToString()%></td>
                    <td><% = suppliers.Telephone.ToString()%></td>                             
                 </tr>
                <% }%>
            <%} %>
            <%else
               {%>
               <tr><td colspan="8">无任何数据</td></tr>
            <%} %>
           
        </table>
     <%=Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id" })%>

 

 

Global中定义路由:

 

//自定义的分页路由,示例项目中的“自定义路由分页”示例中用
            routes.MapRoute("Paging", "{controller}/{action}/employee_{employeeId}/page_{pageIndex}",
                            new
                            {
                                controller = "Orders",
                                action = "EmployeeOrders",
                                emplyeeId = "1",
                                pageIndex = UrlParameter.Optional
                            });

 

 

posted @ 2013-10-19 09:42  kongfl888  阅读(201)  评论(0编辑  收藏  举报