Fix: Getting rid of weird Asp.Net MVC 3 “?area=” links

This is potentially a fix without a problem, but…

Using syntax like this (I’m using T4MVC here):

@Html.ActionLink("Home", MVC.Home.Index())

I expect to have the link rendered as:


Yet, sometimes, it would render as:


WTF?  What’s with that?  There is (AFAIKT) no functional difference between them, but I found it annoying.

My google-fu failed me for quite a while until I saw a random comment in some post and found that if I used this syntax:

<a href="@Url.Action("Index", "Home")">Home</a>

I always got the right rendered link.

Why?  I don’t know.  I feel like I should know.  I thought it might have to do with RenderPartial vs. something else, but that didn’t seem to be it.   I’m tempted to say it is due to T4MVC, but don’t know why it would be specifically.

Anyway, just a note to myself that, if I’m feeling anal about links, this gets rid of the issue.

posted on Sunday, January 22, 2012 12:27 AM Print
# re: Fix: Getting rid of weird Asp.Net MVC 3 “?area=” links
Dan Martin
1/23/2012 9:15 PM
I ran into something similar a while back and also ended up doing Url.Action to get it to work correctly. By time I got it working I wasn't in the mood to go figure out the why or how.

Post Comment

Title *
Name *
Comment *  
Please add 3 and 1 and type the answer here: