In an ASP.NET MVC view I'd like to include a link of the form:
<a href="blah">Link text <span>with further descriptive text</span></a>
Trying to include the <span>
element in the linkText
field of a call to Html.ActionLink()
ends up with it being encoded (as would be expected).
Are there any recommended ways of achieving this?
Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.
Use @Html. ActionLink("Menus", "Menu", "yourController", null, new { @class = "page-scroll" }) and add a controller method named Menu that return the view.
Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
You could use Url.Action to build the link for you:
<a href="<% =Url.Action("Action", "Controller")%>">link text <span>with further blablah</span></a>
or use Html.BuildUrlFromExpression:
<a href="<% =Html.BuildUrlFromExpression<Controller>(c => c.Action()) %>">text <span>text</span></a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With