1

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

<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)

如果尝试了各种路线并阅读了各种帖子,但找不到任何适用于我的东西。

任何人都可以提供一些帮助吗?

谢谢鲁迪

4

1 回答 1

1

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

routes.MapRoute(
            "MyRouteName",                                              // Route name
            "{controller}/{action}/{id}/{section}/{subsection}",                           // URL with parameters
            new { controller = "Home", action = "Index", id= "", section= "", subsection = "" }  // Parameter defaults
        );
于 2012-05-23T14:34:33.097 回答