Reputation: 1481
I've recently been looking into the areas functionality for my application and had partial success transferring code into my first area.
My question involves linking from inside an area to a location that isn't in an area. I've read the tutorial on how to link from one area to another, but while I still have code that isn't within an area how do I link to it?
<a href="@Url.Action("Index","Home", new )"> <span>Testing Link </span> </a>
How do I make this code, which currently links to /myarea/home/index instead link to /home/index (not in an area). If this is against best practices I'd be interesting in reading about it, I'm still learning ASP.NET's version of Areas
Upvotes: 2
Views: 249
Reputation: 27585
link to an area:
@Url.Action("Index","Home", new { area = "YourAreaName" } )
link to a place out of any area:
@Url.Action("Index","Home", new { area = "" } )
A helpful list:
@Html.ActionLink("LinkText", "ActionName", new { area = "AreaName" })
@Html.ActionLink("LinkText", "ActionName", new { area = "" })
@Html.ActionLink("LinkText", "ActionName", "ControllerName", new { area = "AreaName" }, new { /* html attributes */ })
@Html.ActionLink("LinkText", "ActionName", "ControllerName", new { area = "" }, new { /* html attributes */ })
<a href="@Url.Action("ActionName", new { area = "AreaName" })">Link Text</a>
<a href="@Url.Action("ActionName", new { area = "" })">Link Text</a>
<a href="@Url.Action("ActionName", "ControllerName", new { area = "AreaName" })">Link Text</a>
<a href="@Url.Action("ActionName", "ControllerName", new { area = "" })">Link Text</a>
Upvotes: 5
Reputation: 69953
The RouteValues
collection can take an area parameter. Just make it blank.
new { area = "" }
Upvotes: 2