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="http://somethinghere.com/page/1"><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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s