tags:

views:

170

answers:

1

currently I have a medium sized MVC project with multiple controllers that support paging through a paging helper.

this works like this

routes.MapRoute(
                "TabletsPaged",
                "Tablet/Page/{page}",
                new { controller = "Tablet", action = "Index" }
            ); //paging in the tablet controller

in my master page i have a nav with a link to all of the index actions of my various controllers. For whatever reason when I change pages on any of my controllers my nav links become /controller/page/x where x is the current page i am viewing, and when in the home controller i the links just appear as /controller. Any ideas why this is going on?

+2  A: 

The routing engine takes the values of placeholder variables in the current route (the view you are on) and automatically adds them to all links generated in that view which also contain these variables.

You need to explicitly reset these variables where you don't need the page numbers, that is, when you generate the links for your menu, like this:

ActionLink ("Tablet", "Index", new { page = "" });


To your problem with weird link: look at the ActionLink signature - you're feeding it the wrong parameter sequence.

To your use this overload gets hit:

ActionLink (string linkText, string actionName, object routeValues,
            object htmlAttributes);

As the third parameter it expects the RouteValues but instead receives a string, while the fourth parameter expects the htmlAttributes and you're giving it the route values.

Use another overload:

ActionLink (string linkText, string actionName, string controllerName,
            object routeValues, object htmlAttributes);

And just give it "null" as the fifth argument if you're not setting any html attributes.

ActionLink("Patients", "Index", "Patient", new {page = ""}, null)
Developer Art
excellent thank you very much
Jimmy
actually one problem, when putting in html.ActionLink("Patients", "Index", "Patient", new {page = ""}) i get some weird link that doesnt work
Jimmy
IE: http://localhost/Project/Users/Page/1?Length=7
Jimmy
I updated my explanation to be more precise on what is happening.
Developer Art
still not working, I'm doing my paging view routes not get variables if that clears it up any
Jimmy
never mind i got it, thank you very much! just needed to add a controller declaration in the new {} section
Jimmy