master page link generation wrong - s#arp architecture
-
12-12-2019 - |
Question
I am using s#arp architecture 2.0 with asp.net mvc 3.0. The razor code in a master page looks like this:
@Html.ActionLink("Logout", "LogOff", "Users", new { style = "color:Blue;" })
For some reason the app does not produce the correct link anymore (to the action logoff of controller users) but rather points to the current controller for the action logoff. I have not changed anything. where do I have to dig to overcome this please?
The generated link looks like this:
CurrentControllerName/LogOff?Length=5
Solution
You are calling a wrong overload of the ActionLink helper. Here's what you do:
@Html.ActionLink(
"Logout", // linkText
"LogOff", // actionName
"Users", // routeValues
new { style = "color:Blue;" } // htmlAttributes
)
It's pretty obvious why this doesn't produce the correct url. You are passing "Users"
which is a string value at the place where the helper expects routeValues
which must represent an anonymous object.
The correct overload is:
@Html.ActionLink(
"Logout", // linkText
"LogOff", // actionName
"Users", // controllerName
null, // routeValues
new { style = "color:Blue;" } // htmlAttributes
)