区域的默认控制器?
这有点像设置默认控制器时遇到问题的重复在MVC 2 RC Area
但是他的回答并不能令我满意,因为它不起作用。
我有以下
/Areas/TestArea/Controllers/HelloController
/Areas/TestArea/Views/Hello/Index
/Controllers/HomeController
/Views/Home/Index
路线:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default2", // Route name
"TestArea/{controller}/{action}/{id}", // URL with parameters
new { controller = "Hello", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
我添加了第二个路线来尝试获取 http://servername/TestArea 到就像 http://servername/TestArea/Hello 一样工作,但没有成功。基本的 http://servername/ 按预期工作。
那么问题是:如何返回一个区域中的默认控制器?
编辑:我上传了一个示例项目来展示我的意思: http://beginningasp.net/TestAsync.zip< /a>
This is sort of a duplicate of Trouble setting a default controller in MVC 2 RC Area
But his answer doesn't satisfy me, because it doesn't work.
I have the following
/Areas/TestArea/Controllers/HelloController
/Areas/TestArea/Views/Hello/Index
/Controllers/HomeController
/Views/Home/Index
With the following routes:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default2", // Route name
"TestArea/{controller}/{action}/{id}", // URL with parameters
new { controller = "Hello", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
I added the second one to try and get http://servername/TestArea to work as if it were http://servername/TestArea/Hello but was met with no success. The basic http://servername/ works as intended.
So the question is: how do you return a default controller in an area?
Edit: I have uploaded a sample project to show what I mean: http://beginningasp.net/TestAsync.zip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在默认路由之前注册Default2路由,并在默认值中设置area=yourareaname
Try to register Default2 route before the default route and set area=yourareaname in the default values