Reputation: 1555
I want to specify the html id
in ActionLink
, but I can't do this:
@html.ActionLink("Controller", "Action", new {@id = "tec"})
because the @id
means that tec
is a value of id
parameter.
On the other hand, if I do
@html.ActionLink("Controller", "Action", new {@class = "tec"})
the result will be:
<a href="Controller/Action" class="tec"></a>
Do you know a way to specify the html id?
I wanna this result:
<a href="Controller/Action" id="tec"></a>
Upvotes: 3
Views: 8470
Reputation: 9271
You have to specifiy also the controller and you can remove the @
before id
@Html.ActionLink("mylink", "Action", "Controller", new {id = "tec"})
That's because the signature you are using is not the one relative to HtmlAttributes, but to the routing values. If you do not want to specify the controller, use this
@Html.ActionLink("mylink", "Action", null, new {id = "tec"})
Upvotes: 9
Reputation: 11916
The method signature in your case should be of this..
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
Object routeValues,
Object htmlAttributes
)
Provide the parameters in the same format. htmlattributes should be for creating new html object.
Upvotes: 1