我有一个名为"UserProfile"的区域.从索引视图我想从根控制器(非区域)调用一个Action.我使用了Html.ActionLink("索引","主页")
当我运行应用程序时,生成的URL是"/ UserProfile/Home/Index"而不是"/ Home/Index".
Root
View Index.aspx
控制器:App/Controller/HomeController
路径:App/Views/Home
区域
视图:Index.aspx
路径:App/Areas/UserProfile/Views/User
ActionLink:Html.ActionLink("Index","Home")
fre*_*tje 14
是的,如果你使用的地区工作,你应该总是指定Area
的ActionLink
链接,一个空的,如果你不希望链接到一个特定的区域,就像这样:
Html.ActionLink("Home", "Index", "Home", new { Area = "" }, new { })
Run Code Online (Sandbox Code Playgroud)
这是必需的,否则,如果您不指定Area
,则将使用用户当前所在的那个.
例如,如果你在页面中ActionLink
没有指定一个,那么只要你留在你的应用程序的根目录中,它就会起作用.从您进入某个区域的那一刻起,链接将生成为,因此将不再起作用.Area
_Layout.cshtml
\currentArea\the_rest_of_the_link
归档时间: |
|
查看次数: |
3182 次 |
最近记录: |