Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP MVC3 insert html tag inside actionlink

I'm new to the ASP MVC3 and I'm using Razor Engine.

My broplem is that I've build my main navigation in form

<nav> <ul> <li><a href=""><b>Link</b></a></li></ul></nav>

So how I can do this with the actionlink? I just need to insert b tag inside a tag.

like image 403
joonasj Avatar asked Mar 15 '12 11:03

joonasj


2 Answers

Replace this:

<a href=""><b>Link</b></a>

With

@Html.ActionLink("<b>Link</b>", "Action", "Controller")

That may auto encode the <b></b>, so you can try:

@Html.ActionLink(new MvcHtmlString("<b>Link</b>").ToHtmlString(), "Action", "Controller")

Even more simply put, you can use @Url.Action("Action", "Controller"), in the link like:

<a href='@(Url.Action("Action", "Controller"))'><b>Link</b></a>
like image 82
Brian Mains Avatar answered Sep 17 '22 06:09

Brian Mains


Use @Url.Action() to get href value instead of @Html.ActionLink

like image 32
Denis Agarev Avatar answered Sep 19 '22 06:09

Denis Agarev