MVC路线问题

时间:2013-05-12 04:44:43

标签: asp.net-mvc-3

我注册了这条路线:

context.MapRoute(
                "Book",
                "book/{id}",
                new { action = "index", controller = "book" },
                new string[] { "Web.Areas.Books.Controllers" }
            );

这样可以提供以下网址: HTTP:///书/ 4f6be481e8f6ae0a9063afe7

现在我有一个url,它是以下任意一个:

http://<domain>/book/4f6be481e8f6ae0a9063afe7/GetFullDescription?app=3
OR
http://<domain>/book/GetFullDescription?app=3&id=4f6be481e8f6ae0a9063afe7

我更喜欢第一条路线。我无法让它发挥作用。 我在书籍控制器中定义了一个动作GetFullDescription。

如果我注册这样的路线,它将进入GetFullDescription动作。

context.MapRoute(
                "BookFullDesc",                
                "book/{action}/{id}",                
                new { action = "index", controller = "book", id = UrlParameter.Optional },
                new string[] { "Web.Areas.Books.Controllers" }
            );

http://<domain>/book/4f6be481e8f6ae0a9063afe7网址中断了

除非我将其更改为 http://<domain>/book/index/4f6be481e8f6ae0a9063afe7&lt; - 注意索引后的索引

修改 我想要的只是一条服务这两个网址的单一路线:

http://<domain>/book/4f6be481e8f6ae0a9063afe7
http://<domain>/book/4f6be481e8f6ae0a9063afe7/GetFullDescription

由于

1 个答案:

答案 0 :(得分:0)

context.MapRoute(
                "Book",
                "book/{id}/{action}",
                new { action = "index", controller = "book", app = 3 },
                new string[] { "Web.Areas.Books.Controllers" }
            );