8

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
joonasj
  • 551
  • 2
  • 6
  • 19

2 Answers2

16

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>
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • One more think on this.... if you tried the above suggestion but you're still seeing the issue it may be because you tried the 3rd suggestion and used Html.Action() as opposed to Url.ACtion() ;) – bbqchickenrobot Feb 19 '13 at 00:53
  • Are you sure the above code is working?? its not working for me. – Rajshekar Reddy Sep 25 '14 at 10:29
  • You got my +1 for the last option. First option got the HTML encoded (as you stated) and the second one does not even compile. – Joel Jan 06 '15 at 17:33
9

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

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Denis Agarev
  • 1,531
  • 4
  • 17
  • 34