是有&QUOT它需要;区域" routevalue上的ActionLink如果应用程序分为领域? [英] Is it required to have "area" routevalue on actionlink if the application was grouped into areas?
问题描述
我有一个名为用户配置的区域。
并从其索引视图我想打电话从根控制器(非区)的行动。
我用Html.ActionLink(指数,家)
I have an area called "UserProfile". And from its Index View I want to call an Action from the root controller (Non-Area). I used Html.ActionLink("Index", "Home")
当我运行应用程序生成的URL为/用户配置/首页/索引,而不是/首页/索引。
When I ran the application the generated url is "/UserProfile/Home/Index" instead of "/Home/Index".
根结果
查看结果的Index.aspx
控制器:应用/控制器/ HomeController的结果
路径:应用程序/查看/首页
Root
View Index.aspx
Controller: App/Controller/HomeController
Path: App/Views/Home
区结果
查看:Index.aspx的结果
路径:应用/区域/用户配置/浏览/搜索用户
ActionLink的:Html.ActionLink(索引,家)
Area
View: Index.aspx
Path: App/Areas/UserProfile/Views/User
ActionLink: Html.ActionLink("Index", "Home")
推荐答案
是的,如果你使用领域工作,你应该的总是的指定区
在 ActionLink的
链接,如果你不希望链接到一个特定的区域空单,是这样的:
Yes, if you're working with areas you should always specify an Area
in ActionLink
links, an empty one if you don't want the link to go to a specific area, like this:
Html.ActionLink("Home", "Index", "Home", new { Area = "" }, new { })
这是必要的,因为否则,如果不指定区
,一来,用户在此刻将被使用。
This is needed because otherwise, if you don't specify an Area
, the one where the user is in at the moment will be used.
如果您例如使用 ActionLink的
,而无需在 _layout指定
页,它将只要你留在你的应用程序的根目录下工作。从你进入一个区域,虽然那一刻,链接将作为区
。 CSHTML \\ currentArea \\ the_rest_of_the_link
生成,因此,就不管用了。
If you for instance use an ActionLink
without specifying an Area
in your _Layout.cshtml
page, it will work as long as you stay in the root of your Application. From the moment you go into an area though, the link will be generated as \currentArea\the_rest_of_the_link
, and hence, won't work anymore.
这篇关于是有&QUOT它需要;区域" routevalue上的ActionLink如果应用程序分为领域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!