title: How To do Routing For Pagination in ASP.NET MVC 5
body: <p>I am doing pagination for an application in ASP.NET MVC 5 and stuck on the routing for the paging. Following is the format I am trying to use:</p>
  
  <pre><code>&lt;a href="~/Home/page/1)"&gt;Next&lt;/a&gt;
  </code></pre>
  
  <p>Right now, it works well with the following:</p>
  
  <pre><code>&lt;a href="~/Home?page=1"&gt;Next&lt;/a&gt;
  </code></pre>
  
  <p>In the RouteConfig file, I've set the following routes:</p>
  
  <pre><code>public static void RegisterRoutes(RouteCollection routes)
      {
          //routes.RouteExistingFiles = true;
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapRoute( //Route For The Pagination
              "Home",
              "Home/page/{page}",
               new { controller = "Home", action = "Index" }
         );
  
          routes.MapRoute( //Default Route
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
      }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    public ActionResult Index(int? page)
      {
          MainDbContext db = new MainDbContext();
  
          var listItems = new List&lt;List&gt;();
  
          if (User.Identity.IsAuthenticated)
          {
              listItems = (db.Lists.ToList());
          }
          else
          {
              listItems = (db.Lists.Where(m =&gt; m.Public == "Yes").ToList());
          }
  
          var pager = new Pager(listItems.Count(), page);
  
          var viewModel = new List
          {
              Items = listItems.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize).ToList(),
              Pager = pager
          };
  
          return View(viewModel);
      }
  </code></pre>
  
  <p>I am not sure if I am doing the right thing. But right now, when I run the application, for the paging section, it shows this message '<strong>Server Error in '/' Application - The resource cannot be found</strong>'. Do I need to configure anything else and would expect suggestions from the experts. Thanks.</p>