To create a hyperlink based on controller action method, we can use Html.ActionLink
helper methods.
@Html.ActionLink("Home using Html.Action", "Index", "Home")
In the above ActionLink method has three parameters
We can also use different overload methods of the Html.ActionLink
to format our hyperlink or apply css styles or pass object parameters as we have passed in the Url.Action method previously.
@Html.ActionLink("Home using Html.Action", "Index", new { controller = "Home" }, new
{ @class = "myCSSCalss", style = "color:red;" })
Above ActionLink method will create a hyperlink with class attribute as “myCSSClass” and style as “color:red”. Notice that the 3rd parameter is explicitly mentioning controller parameter as “Home” as in this overload method the 3rd parameter is the object parameter.
To get only url of the action method, use Url.Action method.