更新到Mvc 3后路由无法正常工作

时间:2012-01-31 17:28:51

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

我刚刚将我的Asp.Net Mvc 2项目更新到Mvc 3,突然我的链接停止了工作。当我打开一个页面时,页面上的所有链接都会重定向回自身。

此外,某些重定向到过去在以前版本中工作的操作不再起作用。它一直说'路由表中没有路由匹配提供的值。'。我使用RouteDebug来查看发生了什么,但找不到任何问题。

更新

这是我正在使用的其中一条路线:

// ** Standard route. **
     context.MapRoute(
        "group_default", // Route name
        "{language}/{organisation}/Research.aspx/{controller}/{action}/{organisationId}/{parameter}/",
        // URL with parameters
        new
        {
           area = "research",
           language = "en-US",
           organisation = "",
           controller = "Home",
           action = "Index",
           organisationId = UrlParameter.Optional,
           parameter = UrlParameter.Optional
        }, // Parameter defaults
        new[] { "Project.Web.Areas.Research.Controllers" }
     );

正如您在下面的回答中所看到的,问题是由两个UrlParameter.Optional引起的。这是Mvc 3中的一个错误

1 个答案:

答案 0 :(得分:2)

哇,经过大约4个小时的调试后我发现了问题:这是Mvc 3中的一个错误。由于这个bug,不可能在彼此之后使用两个UrlParameter.Optional。 Phil Haack有一篇很好的博客文章:http://haacked.com/archive/2011/02/20/routing-regression-with-two-consecutive-optional-url-parameters.aspx

希望这会有所帮助(并节省一些时间)