MvcPager分页控件
MvcPager 自定义路由表分页示例—雇员的订单
本示例演示如何使用MvcPager分页控件实现自定义路由分页,分页代码:
<%=Html.Pager(Model,null,"Paging",null ) %>
路由定义如下:
routes.MapRoute("Paging", "{controller}/{action}/employee_{employeeId}/page_{pageIndex}",
new { controller = "Orders", action = "CustomRouteTable", emplyeeId = "1", pageIndex = UrlParameter.Optional });
<%=Html.Pager(Model,null,"Paging",null ) %>
路由定义如下:
routes.MapRoute("Paging", "{controller}/{action}/employee_{employeeId}/page_{pageIndex}",
new { controller = "Orders", action = "CustomRouteTable", emplyeeId = "1", pageIndex = UrlParameter.Optional });
| 订单编号 | 订单日期 | 顾客编号 | 收货地址 |
|---|---|---|---|
| 10770 | 1997/12/9 0:00:00 | HANAR | Rua do Paço, 67 |
| 10786 | 1997/12/19 0:00:00 | QUEEN | Alameda dos Canàrios, 891 |
| 10795 | 1997/12/24 0:00:00 | ERNSH | Kirchgasse 6 |
| 10811 | 1998/1/2 0:00:00 | LINOD | Ave. 5 de Mayo Porlamar |
| 10824 | 1998/1/9 0:00:00 | FOLKO | Åkergatan 24 |
| 10844 | 1998/1/21 0:00:00 | PICCO | Geislweg 14 |
| 10845 | 1998/1/21 0:00:00 | QUICK | Taucherstraße 10 |
| 10852 | 1998/1/26 0:00:00 | RATTC | 2817 Milton Dr. |
| 10857 | 1998/1/28 0:00:00 | BERGS | Berguvsvägen 8 |
| 10862 | 1998/1/30 0:00:00 | LEHMS | Magazinweg 7 |
| 10883 | 1998/2/12 0:00:00 | LONEP | 89 Chiaroscuro Rd. |
| 10887 | 1998/2/13 0:00:00 | GALED | Rambla de Cataluña, 23 |
| 10932 | 1998/3/6 0:00:00 | BONAP | 12, rue des Bouchers |
| 10940 | 1998/3/11 0:00:00 | BONAP | 12, rue des Bouchers |
| 10955 | 1998/3/17 0:00:00 | FOLKO | Åkergatan 24 |
| 10957 | 1998/3/18 0:00:00 | HILAA | Carrera 22 con Ave. Carlos Soublette #8-35 |
| 10961 | 1998/3/19 0:00:00 | QUEEN | Alameda dos Canàrios, 891 |
| 10962 | 1998/3/19 0:00:00 | QUICK | Taucherstraße 10 |
| 10977 | 1998/3/26 0:00:00 | FOLKO | Åkergatan 24 |
| 10979 | 1998/3/26 0:00:00 | ERNSH | Kirchgasse 6 |
共2页34条订单
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<PagedList<Order>>" %>
<%@ Import Namespace="MvcPagerSample.Models" %>
<%@ Import Namespace="Webdiyer.WebControls.Mvc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
MvcPager 自定义路由表分页示例
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>MvcPager 自定义路由表分页示例—雇员的订单</h2>
<div>本示例演示如何使用MvcPager分页控件实现自定义路由分页,分页代码:<br />
<%=Html.Pager(Model,null,"Paging",null ) %>
<br /><strong>路由定义如下:</strong><br />
routes.MapRoute("Paging", "{controller}/{action}/employee_{employeeId}/page_{pageIndex}",
<br /> new { controller = "Orders", action = "EmployeeOrders",
emplyeeId = "1", pageIndex = UrlParameter.Optional });
</div><br />
<div>雇员编号:
<%
int empId = Convert.ToInt32(ViewContext.RouteData.Values["employeeId"]);
for(int i=1;i<10;i++)
{
if (empId == i)
Response.Write("雇员" + i);
else
Response.Write(Html.RouteLink("雇员" + i,"Paging",
new RouteValueDictionary { { "action", "EmployeeOrders" },
{"controller","Orders"}, { "employeeId", i }, { "pageIndex", 1 } },null));
Response.Write(" ");
} %>
</div>
<table width="98%">
<tr><th>订单编号</th><th>订单日期</th><th>顾客编号</th><th>收货地址</th></tr>
<%foreach(Order od in Model)
{
%>
<tr><td><%=od.OrderID %></td><td><%=od.OrderDate.ToString() %></td>
<td><%=od.CustomerID %></td><td><%=od.ShipAddress %></td></tr>
<%
} %>
</table>
<div style="float:left;width:30%"><%="共"+Model.TotalPageCount+"页"+
Model.TotalItemCount+"条订单" %>
</div><div style="float:right">
<%=Html.Pager(Model,null,"Paging",null )%></div>
</asp:Content>
public ActionResult CustomRouteTable(int employeeId, int? pageIndex)
{
using(var db=new MvcPagerSampleDataContext())
{
PagedList<Order> pagedOrders =
db.Orders.Where(o => o.EmployeeID == employeeId).ToPagedList(pageIndex ?? 1, 20);
return View(pagedOrders);
}
}
