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 });
| 订单编号 | 订单日期 | 顾客编号 | 收货地址 |
|---|---|---|---|
| 10771 | 1997/12/10 0:00:00 | ERNSH | Kirchgasse 6 |
| 10782 | 1997/12/17 0:00:00 | CACTU | Cerrito 333 |
| 10799 | 1997/12/26 0:00:00 | KOENE | Maubelstr. 90 |
| 10828 | 1998/1/13 0:00:00 | RANCH | Av. del Libertador 900 |
| 10829 | 1998/1/13 0:00:00 | ISLAT | Garden House Crowther Way |
| 10837 | 1998/1/16 0:00:00 | BERGS | Berguvsvägen 8 |
| 10849 | 1998/1/23 0:00:00 | KOENE | Maubelstr. 90 |
| 10853 | 1998/1/27 0:00:00 | BLAUS | Forsterstr. 57 |
| 10871 | 1998/2/5 0:00:00 | BONAP | 12, rue des Bouchers |
| 10889 | 1998/2/16 0:00:00 | RATTC | 2817 Milton Dr. |
| 10893 | 1998/2/18 0:00:00 | KOENE | Maubelstr. 90 |
| 10905 | 1998/2/24 0:00:00 | WELLI | Rua do Mercado, 12 |
| 10942 | 1998/3/11 0:00:00 | REGGC | Strada Provinciale 124 |
| 10951 | 1998/3/16 0:00:00 | RICSU | Starenweg 5 |
| 10953 | 1998/3/16 0:00:00 | AROUT | Brook Farm Stratford St. Mary |
| 10963 | 1998/3/19 0:00:00 | FURIB | Jardim das rosas n. 32 |
| 10970 | 1998/3/24 0:00:00 | BOLID | C/ Araquil, 67 |
| 10978 | 1998/3/26 0:00:00 | MAISD | Rue Joseph-Bens 532 |
| 11016 | 1998/4/10 0:00:00 | AROUT | Brook Farm Stratford St. Mary |
| 11017 | 1998/4/13 0:00:00 | ERNSH | Kirchgasse 6 |
共2页22条订单
<%@ 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);
}
}
