Question

I'm trying to implement some simple paging, based on How do I do pagination in ASP.NET MVC?

The paging works fine.

However, I'm now trying to create previous and next links, but can't figure out how to access the params:

My route looks like:

  routes.MapRoute(
      "Name",
      "Controller/ActionName/{pageID}",
      new { controller = "Controller", action = "ActionName" , pageID = 0 },
      new { pageID = @"\d*"}
      );

And my next link looks like:

   <%=Html.ActionLink("next page", "ActionName", "Controller", new {pageID = pageID + 1 }, null) %>

The error I get is:

 Compiler Error Message: CS0103: The name 'pageID' does not exist in the current context

How should I create the Prev/Next links (or, in this case, just the next)?

Was it helpful?

Solution

The error is occurring on the second PageID in

new {pageID = pageID + 1 }, ...

If you want to reference pageID in this way, you have to pass it in as part of your model.

Have a look at the following tutorial:

NerdDinner Step 8: Paging Support
http://nerddinnerbook.s3.amazonaws.com/Part8.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top