I am trying to set the color of the hyperlink returned by Html.ActionLink
in a Razor page. I want it to be red.
I tried setting HTML attributes when calling ActionLink
:
Html.ActionLink("Home", "Index", "Home", new { style = "color: red;" })
But it didn't give a visible effect.
The strange thing is that only ActionLink
behaves badly. I tried calling the Label
method, and the label was red, as I set in the HTML attributes.
If I use the a
tag instead of that method, everything will work properly. But using method is more convenient for me. I hope it will again be a stupid error and I will be able to use ActionLink
again.
CodePudding user response:
Html.ActionLink("Home", "Index", "Home", new { style = "color: red;" })
the signature like below:
public static string ActionLink(this HtmlHelper htmlHelper,
string linkText,
string actionName,
string controllerName,
object values,
object htmlAttributes)
You may miss the routeValues
, try to do like this:
@Html.ActionLink("Home", "Index", "Home",null,new { style="color: red;"})
result: