here is the procedure to duplicate the issue.
add the following lines to the RegisterRoutes() method just before the "Default" route
routes.MapRoute(
name: "Test",
url: "Test/{action}",
defaults: new { controller = "Test", action = "Index" }
);
add the following to Index.cshtml and About.cshtml
@Html.RouteLink("link to TestController", "Test")
As you can see that the generated html code is different for the 2 pages. I would expect the URL is "/Test" which is rendered correctly for Index.cshtml, but it become "/Test/About" for About.cshtml.
My question is if there is any documented way to generate the same correct URL. The above example is created just for demonstration purpose. I would like to use the routing table information to generate menu.
It seems the engine is setting the action
route value from the current page ("Index", "About"). So one way to fix this is to "unset" that route value:
@Html.RouteLink("link to Test Controller", "Test", new { action = String.Empty })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With