MVC路由错误404

Nov*_*ato 2 asp.net-mvc asp.net-mvc-routing

我究竟做错了什么?

我的默认/用户路线

  routes.MapRoute(
            "User", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new {controller = "User", action = "Index", id = UrlParameter.Optional} // Parameter defaults
            );
Run Code Online (Sandbox Code Playgroud)

我想分开代码,所以我创建了另一个控制器"UserProducts"

我的路线

 routes.MapRoute(
            "UserProducts", // Route name
            "user/products/{action}/{id}", // URL with parameters
            new { controller = "UserProducts", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
Run Code Online (Sandbox Code Playgroud)

我的UserProducts控制器中有ActionResult索引,但是我的

localhost/user/products
Run Code Online (Sandbox Code Playgroud)

不起作用:

Error 404 - The resource cannot be found.
Run Code Online (Sandbox Code Playgroud)

Jus*_*gan 5

你可能有错误的顺序.注册这些路由的顺序很重要,第一个映射将覆盖后面的路由.把这UserProducts条线放在一条线上方User.