ASP.NET MVC3领域

Val*_*ris 2 asp.net-mvc-3

我最近一直在研究我的应用程序的区域功能,并且部分成功地将代码转移到我的第一个区域.

我的问题涉及从区域内部到不在区域内的位置的链接.我已经阅读了关于如何从一个区域链接到另一个区域的教程,但是当我仍然有一个不在某个区域内的代码时,如何链接到它?

<a href="@Url.Action("Index","Home", new )">
     <span>Testing Link </span>
</a>
Run Code Online (Sandbox Code Playgroud)

如何创建此代码,当前链接到/ myarea/home/index而不是链接到/ home/index(不在某个区域中).如果这是违反最佳实践的,我会很有兴趣阅读它,我仍然在学习ASP.NET的Area版本

jav*_*iry 5

链接到某个区域:

@Url.Action("Index","Home", new { area = "YourAreaName" } )
Run Code Online (Sandbox Code Playgroud)

链接到任何地区以外的地方:

@Url.Action("Index","Home", new { area = "" } )
Run Code Online (Sandbox Code Playgroud)

一个有用的清单:

@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>
Run Code Online (Sandbox Code Playgroud)