Fork me on GitHub

MvcPager demo - First page url SEO

This sample demonstrates MvcPager's SEO functionality for the first page url.

Note the differences of the first page url of the two MvcPagers bellow.

Order ID Customer ID Company Name Employee Name
10780 LILAS LILA-Supermercado Andrew Fuller
10781 WARTH Wartian Herkku Andrew Fuller
10782 CACTU Cactus Comidas para llevar Anne Dodsworth
10783 HANAR Hanari Carnes Margaret Peacock
10784 MAGAA Magazzini Alimentari Riuniti Margaret Peacock
First page url SEO is not enabled (default):
First Prev 1 2 3 4 5 6 7 8 9 10 ... Next Last 
First page url SEO is enabled (FirstPageRouteName = "MvcPager_Default"):
First Prev 1 2 3 4 5 6 7 8 9 10 ... Next Last 

View:

        
@model PagedList<Order>
@Html.Partial("_DataTable", Model)
<h6><strong>First page url SEO is not enabled (default):</strong></h6>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", RouteName = "MvcPager_SEO", PagerItemTemplate = "{0}&nbsp;" })
<h6><strong>First page url SEO is enabled (FirstPageRouteName = "MvcPager_Default"):</strong></h6>
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", RouteName = "MvcPager_SEO",FirstPageRouteName = "MvcPager_Default", PagerItemTemplate = "{0}&nbsp;"})

Routes:

routes.MapRoute("MvcPager_Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new { id = @"\d*" });
routes.MapRoute("MvcPager_SEO", "{controller}/{action}/page_{id}", new { controller = "Demo", action = "FirstPageUrl", id = 1 }, new { action = "FirstPageUrl" });

_DataTable.cshtml:

@model PagedList<order>
<table class="table table-striped table-bordered">
    <tr>
    <th class="nowrap">
            @Html.DisplayNameFor(model => model.OrderId)
        </th>
    <th class="nowrap">
            @Html.DisplayNameFor(model => model.CustomerId)
        </th>
    <th class="nowrap">
            @Html.DisplayNameFor(model => model.CompanyName)
        </th>
    <th class="nowrap">
            @Html.DisplayNameFor(model => model.EmployeeName)
        </th>
    </tr>
    @foreach (var item in Model)
    {
    <tr>
    <td>
                @Html.DisplayFor(modelItem => item.OrderId)
            </td>
    <td>
                @Html.DisplayFor(modelItem => item.CustomerId)
            </td>
    <td>
                @Html.DisplayFor(modelItem => item.CompanyName)
            </td>
    <td>
                @Html.DisplayFor(modelItem => item.EmployeeName)
            </td>
        </tr>
    }
</table>

Model:

    public class Order
    {
        [Display(Name = "Order ID")]
        public int OrderId { get; set; }
        [Display(Name = "Customer ID"),StringLength(20)]
        public string CustomerId { get; set; }
        [Display(Name = "Order Date")]
        public DateTime OrderDate { get; set; }
        [Display(Name = "Company Name"), StringLength(20)]
        public string CompanyName { get; set; }
        [Display(Name = "Employee Name"), StringLength(20)]
        public string EmployeeName { get; set; }
    }

Controller:

        
        public ActionResult FirstPageUrl(int id = 1)
        {
            using (var db = new DataContext())
            {
                return View(db.Orders.OrderBy(o=>o.OrderId).ToPagedList(id, 5));
            }
        }