MVC 3 路由到区域

发布于 2024-11-16 14:17:14 字数 133 浏览 5 评论 0原文

一条路线如何从一个区域到另一个区域?

在默认项目中,没有区域,但是一旦添加区域,我如何从默认主页重定向到新区域内的页面?

我没有看到 RedirectTo* 方法在任何地方采用区域名称参数。 除非我完全错过了区域的要点?

How does one Route from one Area to another?

In the default project, there are no area's, but once you add an Area, how could I redirect from the default Home page to a page inside my new Area?

I don't see a RedirectTo* method which takes a parameter for an Area name anywhere.
Unless I'm missing the point of Area's completely?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似最初 2024-11-23 14:17:14

在我们的视图中,我们在生成时不需要指定区域路线数据值
链接到该区域内的其他控制器操作。我们只提供操作名称,因为控制器和区域名称将来自当前请求的现有路由数据。如果我们想链接到外部区域,我们需要明确提供该路线数据。

return RedirectToAction("yourAction", "YourController", new { area = "yourArea" });

“area”路由值需要与 AreaRegistration 类中使用的 AreaName 相匹配,才能正确生成 URL。

Inside our views, we don’t need to specify the area route data value when generating
links to other controller actions inside that area. We only supply the action name, because the controller and area name will come from the existing route data for the current request. If we want to link to an outside area, we’ll need to supply that route data explicitly.

return RedirectToAction("yourAction", "YourController", new { area = "yourArea" });

The "area" route value needs to match the AreaName used in the AreaRegistration class for the URL to generate correctly.

要走干脆点 2024-11-23 14:17:14

您视图中的此代码会将您链接到管理区域,无论您当前位于哪个区域:

@Html.ActionLink("Click Me", "ActionName","ControllerName",new { Area = "AreaName"}, null )

例如(糟糕的示例)

@Html.ActionLink("Administer User", "Home","UserAdmin",new { Area = "Admin"}, null )

调用中的最后一个 null 对应于 HtmlAttributes,我通常会离开它为空。

This code in your view will link you to the Admin area, regardless of which area you are currently in:

@Html.ActionLink("Click Me", "ActionName","ControllerName",new { Area = "AreaName"}, null )

e.g. (poor made up example)

@Html.ActionLink("Administer User", "Home","UserAdmin",new { Area = "Admin"}, null )

The final null in the call corresponds to HtmlAttributes, and I usually leave it as null.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文