Nesting Tags inside an Anchor Tag in ASP.NET MVC

I’ve been working on an ASP.NET MVC project and needed to nest an <h2> element inside of an anchor tag because of a CSS-only menu I am using.

<a href=""><h2>Link Text</h2></a>

If you use the traditional ActionLink method in ASP.NET MVC, you can’t do that. At least, I haven’t found a way how.

I did find a work-around, courtesy of Stack Overflow:

<a href="<%= Url.Action("show", "page", new { id = Parentpage.Id }) %>"><h2><%= Parentpage.PageName %></h2></a>

It’s a hack, but it produces the correct output.

Leave a Reply