路由到 ASP.NET MVC 中的区域主页
我正在尝试路由到 MVC 中某个区域的主页,例如
myDomain.com/myArea/Home/Index
,当我使用 URL 时:
myDomain.com/myArea
MVC 似乎是通过尝试在根控制器文件夹中查找名为“myArea”的控制器,从而路由到:
myDomain.com/myArea/Index
如果控制器存在过。
再次,我想要:
myDomain.com/myArea
路由到:
myDomain.com/myArea/Home/Index
我认为我应该能够在 Global.asax 中执行此操作,而不必创建一个重新路由到区域控制器的虚拟控制器,但我画了一个空白。
I'm trying to route to the home page of an Area in MVC, e.g.
myDomain.com/myArea/Home/Index
when I use the URL:
myDomain.com/myArea
MVC appears to by trying to find a Controller called "myArea" in the root Controllers folder and thereby would route to:
myDomain.com/myArea/Index
if the Controller existed.
Again, I want:
myDomain.com/myArea
to route to:
myDomain.com/myArea/Home/Index
I figure that I should be able to do this in Global.asax without having to resort to creating a dummy controller that re-routes to the area controller, but I've drawn a blank.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用来解决这个问题的一种方法是在 Global RegisterRoutes 方法中的默认路由上设置名称空间属性,这似乎可以解决该问题。必须将此限制添加到我在主网站和该区域的控制器之间发生冲突的其他一些路线。
One way I used to get around this was to set the namespaces property on the default route in the Global RegisterRoutes method, this seemed to resolve that problem. Had to add this restriction to some other routes where I had conflicts between Controller in the main website and the area.