This is effectively a duplicate of How Can I Stop ASP.Net MVC Html.ActionLink From Using Existing Route Values?
According to @Eilon -
Because once you invalidate a parameter segment then all parameter segments after it will get invalidated.
In my case, I have two Action links that link to actions on separate controllers.
Both actions have an optional page parameter.
The route configurations look like:
// blog routes
routes.MapRoute(
"",
"blog/page{page}",
new { controller = "Blog", action = "Index" },
new { page = @"\d+" }
);
routes.MapRoute(
"",
"blog/{id}",
new { controller = "Blog", action = "Post" }
);
routes.MapRoute(
"",
"blog",
new { controller = "Blog", action = "Index" }
);
// project routes
routes.MapRoute(
"",
"projects/page{page}",
new { controller = "Project", action = "Index" },
new { page = @"\d+" }
);
routes.MapRoute(
"",
"projects/{id}",
new { controller = "Project", action = "Project" }
);
routes.MapRoute(
"",
"projects",
new { controller = "Project", action = "Index" }
);
The problem is that if I navigate to page 2 of projects, and click the blog link, I will be directed to /blog/page2.
Now according to the above, if a parameter segment is invalidated (in this case both the controller and action are different) then the page parameter should be invalidated. Does this work if the controller and action are specified using the standard ActionLink overloads, or does it only apply if they are passed in via the RouteValueDictionary?
Currently I have had to create a custom ActionLink to remove the "page" parameter from RouteData.
Thanks, Ben