views:

214

answers:

1

I'm trying to implement some simple paging, based on http://stackoverflow.com/questions/446196/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)?

A: 

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

Robert Harvey
Is it still possible to use this approach using a strongly-typed views?I'm getting an error saying 'System.Collections.Generic.IEnumerable<myEntityType>' does not contain a definition for 'HasPreviousPage'
chris
Look closely at the model NerdDinner is using. There is more than one object in there.
Robert Harvey
So what it comes down to is that I can't do what I want to do. I have no real issues with using ViewData, I was just hoping there was a simple way to access the route variables. Thanks.
chris
To access the route variables, use `this.ViewContext.RouteData`. http://stackoverflow.com/questions/1134776/how-do-you-access-the-current-routedata-from-view-in-net-mvc
Robert Harvey