I am trying to implementation the same pagination that is used in the NerdDinner ASP.NET. I am receiving the following error in my view, whenever the pagination starts to kick in.
"A route named 'Index' could not be found in the route collection."
The error is happening on Line 64.
Line 62: <% if (this.Model.HasNextPage)
Line 63: { %>
Line 64: <%= this.Html.RouteLink("Next Page >>>", "Index", new { page = (this.Model.PageIndex + 1) })%>
Line 65: <% } %>
Line 66: </div>
My controller code is:
[Authorize]
public ActionResult Index(int? page)
{
const int pageSize = 25;
var topics = this.TopicRepository.FindAllTopics();
var paginatedTopics = new PaginatedList<Topic>(topics, page ?? 0, pageSize);
return this.View(paginatedTopics);
}
My view code is ...
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CreativeLogic.Sauron.WebMvc.Helpers.PaginatedList<CreativeLogic.Sauron.WebMvc.Models.Topic>>" %>
<!-- Code to display the list here -->
<div class="pagination">
<% if (this.Model.HasPreviousPage)
{ %>
<%= this.Html.RouteLink("<<< Previous Page",
"Index", new { page = (this.Model.PageIndex - 1) }) %>
<% } %>
<% if (this.Model.HasNextPage)
{ %>
<%= this.Html.RouteLink("Next Page >>>",
"Index", new { page = (this.Model.PageIndex + 1) })%>
<% } %>
</div>
This is my first attempt at doing the pagination in ASP.NET MVC ... if there is a better way, please let me know, otherwise, where am I going wrong here?
Thanks much!