MVC 3 路由到区域
一条路线如何从一个区域到另一个区域?
在默认项目中,没有区域,但是一旦添加区域,我如何从默认主页重定向到新区域内的页面?
我没有看到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我们的视图中,我们在生成时不需要指定区域路线数据值
链接到该区域内的其他控制器操作。我们只提供操作名称,因为控制器和区域名称将来自当前请求的现有路由数据。如果我们想链接到外部区域,我们需要明确提供该路线数据。
“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.
The "area" route value needs to match the AreaName used in the AreaRegistration class for the URL to generate correctly.
您视图中的此代码会将您链接到管理区域,无论您当前位于哪个区域:
例如(糟糕的示例)
调用中的最后一个 null 对应于
HtmlAttributes
,我通常会离开它为空。This code in your view will link you to the Admin area, regardless of which area you are currently in:
e.g. (poor made up example)
The final null in the call corresponds to
HtmlAttributes
, and I usually leave it as null.