panjo
panjo

Reputation: 3515

make routing be more generic, pagination

I have enabled pagination and routing settings in global.asax like this

routes.MapRoute("Users", "Index/{page}",
                new { controller = "Users", action = "Index", page = UrlParameter.Optional },
                new[] { "MyProject.Controllers" });

Now I need to apply these to every controller which sends page parameter. How can I do this?

Thank you

Upvotes: 0

Views: 89

Answers (1)

McGarnagle
McGarnagle

Reputation: 102753

There are two ways you can approach it.

  • Add a page parameter to all your Action methods:
    public ActionResult SomeAction(int? page)`
    {
       if (page.HasValue) ...
    }
  • Access the RouteData directly using:
    RouteData.Values["page"]

I guess you might want to consider creating a Base Controller that handles repetitive tasks related to paging.

Upvotes: 1

Related Questions