日期:2014-05-18  浏览次数:20450 次

MVC路由错误,生成http://localhost:59786/MyGet/Get/1?pid=1&page=1
怎么是生成http://localhost:59786/MyGet/Get/1?pid=1&page=1?

应该是http://localhost:59786/MyGet/Get/1/1/1这样的吧?


C# code

            routes.MapRoute(
                "MyGet", // Route name
                "{controller}/{action}/{pid}/{id}/{page}", // URL with parameters
                new { controller = "MyGet", action = "Index", pid = UrlParameter.Optional, id = UrlParameter.Optional, page = UrlParameter.Optional } // Parameter defaults
            );



------解决方案--------------------
试过,代码是没有问题的。。。生成正常。。

你检查下是不是你的MyGet在Default的后面了?要把你的放前面才可以

C# code


routes.MapRoute(
                "MyGet", // Route name
                "{controller}/{action}/{pid}/{id}/{page}", // URL with parameters
                new { controller = "Home", action = "Index", pid = UrlParameter.Optional, id = UrlParameter.Optional, page = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );