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 });
| 订单编号 | 订单日期 | 顾客编号 | 收货地址 |
|---|---|---|---|
| 10900 | 1998/2/20 0:00:00 | WELLI | Rua do Mercado, 12 |
| 10902 | 1998/2/23 0:00:00 | FOLKO | Åkergatan 24 |
| 10909 | 1998/2/26 0:00:00 | SANTG | Erling Skakkes gate 78 |
| 10910 | 1998/2/26 0:00:00 | WILMK | Keskuskatu 45 |
| 10916 | 1998/2/27 0:00:00 | RANCH | Av. del Libertador 900 |
| 10921 | 1998/3/3 0:00:00 | VAFFE | Smagsloget 45 |
| 10928 | 1998/3/5 0:00:00 | GALED | Rambla de Cataluña, 23 |
| 10946 | 1998/3/12 0:00:00 | VAFFE | Smagsloget 45 |
| 10950 | 1998/3/16 0:00:00 | MAGAA | Via Ludovico il Moro 22 |
| 10952 | 1998/3/16 0:00:00 | ALFKI | Obere Str. 57 |
| 10968 | 1998/3/23 0:00:00 | ERNSH | Kirchgasse 6 |
| 10969 | 1998/3/23 0:00:00 | COMMI | Av. dos Lusíadas, 23 |
| 10975 | 1998/3/25 0:00:00 | BOTTM | 23 Tsawassen Blvd. |
| 10976 | 1998/3/25 0:00:00 | HILAA | Carrera 22 con Ave. Carlos Soublette #8-35 |
| 10981 | 1998/3/27 0:00:00 | HANAR | Rua do Paço, 67 |
| 10984 | 1998/3/30 0:00:00 | SAVEA | 187 Suffolk Ln. |
| 10991 | 1998/4/1 0:00:00 | QUICK | Taucherstraße 10 |
| 10992 | 1998/4/1 0:00:00 | THEBI | 89 Jefferson Way Suite 2 |
| 10995 | 1998/4/2 0:00:00 | PERIC | Calle Dr. Jorge Cash 321 |
| 11012 | 1998/4/9 0:00:00 | FRANK | Berliner Platz 43 |
共3页49条订单
<%@ 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);
}
}
