mvc3地图路线

时间:2012-05-23 14:24:05

标签: asp.net asp.net-mvc-3 routes

我希望使用以下网址并相应地映射一些路线

<domain>/Home/About
<domain>/Home/SiteList
<domain>/Site/<id>/ (this one is defaulted to the details view)
<domain>/Site/<id>/section1/ (this one goes to section1 route in the Site controller)
<domain>/Site/<id>/section2/ (this one goes to section2 route in the Site controller)

e.g.
<domain>/Site/london/siteinfo

上述内容由

涵盖
routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } //     Parameter defaults
        );

但是,我也想使用以下路线

<domain>/Site/<siteid>/section1/controller/action (where controller gets data linked to the <siteid> and action is optional)

示例链接是:

<domain>/Site/london/siteinfo/manager (manager is a controller and will list managers for the site)

如果尝试过各种路线并阅读各种帖子但找不到适用于我的任何内容。

有人可以提供一些帮助吗?

由于 鲁迪

1 个答案:

答案 0 :(得分:1)

在“默认”下添加一条路线:

routes.MapRoute(
            "MyRouteName",                                              // Route name
            "{controller}/{action}/{id}/{section}/{subsection}",                           // URL with parameters
            new { controller = "Home", action = "Index", id= "", section= "", subsection = "" }  // Parameter defaults
        );