Reputation: 7766
In a mvc project there are two controller
HomeController
Contain a view client
EndorsementController
Contain a View add
from the add
view in EndorsmentController
I wrote an actionlink as below
@Html.ActionLink("Back to Home", "client", "Home", new { @style = "color: #FFF" })
but when ever I click this actionlink it is looking for a URL
Endorsement/client
Actually it should be
Home/Client
Why it is not taking the correct controller name? Anything I am missing?
Upvotes: 0
Views: 198
Reputation: 26028
You are using the wrong ActionLink
overload method. You can try the following code in your view:
@Html.ActionLink("Back to Home", "client", "Home", null, new { @style = "color: #FFF" })
The rendered HTML will look something like this:
<a href="/Home/client" style="color: #FFF">Back to Home</a>
Just a pointer try to capitalise your view names, instead of using client
try Client
. Both will work.
Upvotes: 3
Reputation: 967
The point to take home is the particular overload you want to use. Since this is the you want to use synthax : //linkText, actionName, controllerName, routeValues, htmlAttributes
the below is how your ActionLink
should look like
@Html.ActionLink("Back to Home", "Client", "Home", null, new { @style = "color: #FFF" })
What you were using before follows this synthax: // linkText, actionName, routeValues, htmlAttributes
which is shown below
@Html.ActionLink("Back to Home", "client", "Home", new { @style = "color: #FFF" })
Hence the Url
confusion
Upvotes: 1
Reputation: 3242
you put your html attribute in "object route values
"
you have to put null
into it
use the following syntax to get correct output:
@Html.ActionLink("Back to Home", "client", "Home", null, new { @style = "color: #FFF" })
Upvotes: 1