2

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

2 Answers 2

5

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>
Sign up to request clarification or add additional context in comments.

Comments

2

The RouteValues collection can take an area parameter. Just make it blank.

new { area = "" }

1 Comment

Simple quick answer, sad I didn't think of this myself, appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.