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 });
| 订单编号 | 订单日期 | 顾客编号 | 收货地址 |
|---|---|---|---|
| 10780 | 1997/12/16 0:00:00 | LILAS | Carrera 52 con Ave. Bolívar #65-98 Llano Largo |
| 10781 | 1997/12/17 0:00:00 | WARTH | Torikatu 38 |
| 10787 | 1997/12/19 0:00:00 | LAMAI | 1 rue Alsace-Lorraine |
| 10798 | 1997/12/26 0:00:00 | ISLAT | Garden House Crowther Way |
| 10805 | 1997/12/30 0:00:00 | THEBI | 89 Jefferson Way Suite 2 |
| 10808 | 1998/1/1 0:00:00 | OLDWO | 2743 Bering St. |
| 10810 | 1998/1/1 0:00:00 | LAUGB | 2319 Elm St. |
| 10815 | 1998/1/5 0:00:00 | SAVEA | 187 Suffolk Ln. |
| 10819 | 1998/1/7 0:00:00 | CACTU | Cerrito 333 |
| 10832 | 1998/1/14 0:00:00 | LAMAI | 1 rue Alsace-Lorraine |
| 10846 | 1998/1/22 0:00:00 | SUPRD | Boulevard Tirou, 255 |
| 10858 | 1998/1/29 0:00:00 | LACOR | 67, avenue de l'Europe |
| 10865 | 1998/2/2 0:00:00 | QUICK | Taucherstraße 10 |
| 10912 | 1998/2/26 0:00:00 | HUNGO | 8 Johnstown Road |
| 10915 | 1998/2/27 0:00:00 | TORTU | Avda. Azteca 123 |
| 10919 | 1998/3/2 0:00:00 | LINOD | Ave. 5 de Mayo Porlamar |
| 10939 | 1998/3/10 0:00:00 | MAGAA | Via Ludovico il Moro 22 |
| 10949 | 1998/3/13 0:00:00 | BOTTM | 23 Tsawassen Blvd. |
| 10967 | 1998/3/23 0:00:00 | TOMSP | Luisenstr. 48 |
| 10971 | 1998/3/24 0:00:00 | FRANR | 54, rue Royale |
共3页44条订单
<%@ 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);
}
}
