Using custom route
This sample demonstrate how to use custom route in MvcPager, syntax:
<%=Html.Pager(Model,null,"Paging",null ) %>
<%=Html.Pager(Model,null,"Paging",null ) %>
Employee NO.:
Employee 1 Employee 2 Employee 3 Employee 4 Employee 5 Employee 6 Employee 7 Employee 8 Employee 9
| Order ID | Order Date | Customer ID | Ship Address |
|---|---|---|---|
| 10771 | 12/10/1997 12:00:00 AM | ERNSH | Kirchgasse 6 |
| 10782 | 12/17/1997 12:00:00 AM | CACTU | Cerrito 333 |
| 10799 | 12/26/1997 12:00:00 AM | KOENE | Maubelstr. 90 |
| 10828 | 1/13/1998 12:00:00 AM | RANCH | Av. del Libertador 900 |
| 10829 | 1/13/1998 12:00:00 AM | ISLAT | Garden House Crowther Way |
| 10837 | 1/16/1998 12:00:00 AM | BERGS | Berguvsvägen 8 |
| 10849 | 1/23/1998 12:00:00 AM | KOENE | Maubelstr. 90 |
| 10853 | 1/27/1998 12:00:00 AM | BLAUS | Forsterstr. 57 |
| 10871 | 2/5/1998 12:00:00 AM | BONAP | 12, rue des Bouchers |
| 10889 | 2/16/1998 12:00:00 AM | RATTC | 2817 Milton Dr. |
| 10893 | 2/18/1998 12:00:00 AM | KOENE | Maubelstr. 90 |
| 10905 | 2/24/1998 12:00:00 AM | WELLI | Rua do Mercado, 12 |
| 10942 | 3/11/1998 12:00:00 AM | REGGC | Strada Provinciale 124 |
| 10951 | 3/16/1998 12:00:00 AM | RICSU | Starenweg 5 |
| 10953 | 3/16/1998 12:00:00 AM | AROUT | Brook Farm Stratford St. Mary |
| 10963 | 3/19/1998 12:00:00 AM | FURIB | Jardim das rosas n. 32 |
| 10970 | 3/24/1998 12:00:00 AM | BOLID | C/ Araquil, 67 |
| 10978 | 3/26/1998 12:00:00 AM | MAISD | Rue Joseph-Bens 532 |
| 11016 | 4/10/1998 12:00:00 AM | AROUT | Brook Farm Stratford St. Mary |
| 11017 | 4/13/1998 12:00:00 AM | ERNSH | Kirchgasse 6 |
2 page(s) 22 orders
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<PagedList<Order>>" %>
<%@ Import Namespace="Webdiyer.Mvc2Demo.Models" %>
<%@ Import Namespace="Webdiyer.WebControls.Mvc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
using custom route
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Using custom route</h2>
<div>This sample demonstrate how to use custom route in MvcPager, syntax:<br />
<%=Html.Pager(Model,null,"Paging",null ) %>
</div><br />
<div>Employee NO.:
<%
int empId = Convert.ToInt32(ViewContext.RouteData.Values["employeeId"]);
for(int i=1;i<10;i++)
{
if (empId == i)
Response.Write("Employee " + i);
else
Response.Write(Html.RouteLink("Employee " + i,"Paging",
new RouteValueDictionary { { "action", "CustomRouteTable" },
{ "controller", "Orders" }, { "employeeId", i },
{ "pageIndex", 1 } }, null));
Response.Write(" ");
} %>
</div>
<table width="98%">
<tr><th>Order ID</th><th>Order Date</th><th>Customer ID</th><th>Ship Address</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+" page(s) "+Model.TotalItemCount+" orders" %>
</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 MvcPagerDemoDataContext())
{
PagedList<Order> pagedOrders =
db.Orders.Where(o => o.EmployeeID == employeeId).ToPagedList(pageIndex ?? 1, 20);
return View(pagedOrders);
}
}
//custom route for paging demo
routes.MapRoute("Paging", "{controller}/{action}/employee_{employeeId}/page_{pageIndex}",
new
{
controller = "Orders",
action = "CustomRouteTable",
employeeId = 1,
pageIndex = UrlParameter.Optional
});