创建特定的路由条目以访问区域内的控制器

时间:2011-08-23 17:22:28

标签: asp.net-mvc asp.net-mvc-routing

我想尝试将所有购物车处理保存在MVC2项目中单独的“区域”内的1个控制器内。

但是,我需要在此控制器中将1个操作暴露给已经存在很长时间的URL,并且该URL不包含对该区域的任何引用。

我的区域和控制器设置为处理看起来像这样的请求(Commerce是区域):

http://www.abc.com/Commerce/Buy/Select

但我必须回复的网址是:

http://www.abc.com/quote/

是否有可能为我创建一个可以解决此问题的一次性路由规则?我知道我可以创建一个名为“Quote”的Controller并将其放在Commerce区域之外,但我宁愿使用路由。

感谢。

2 个答案:

答案 0 :(得分:2)

你试过这个吗?

        routes.MapRoute(
            "Quote", // Route name
            "/Quote/{id}", // URL with parameters
            new { area="Commerce", controller = "Buy", action = "Quote", id = UrlParameter.Optional } // Parameter defaults
        );

答案 1 :(得分:1)

抱歉,简单如下:

        routes.MapRoute(
            "Quote", // Route name
            "Quote/", // URL with parameters
            new { area = "Commerce", controller = "Buy", action = "Select" } // Parameter default
            );