.NET MVC路由问题

出于某种原因,.NET没有看到我的路线 .

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

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

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


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

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

        routes.MapRoute(
         "ViewArticle", // Route name
         "{controller}/{action}/{id}/{friendly}", // URL with parameters
         new {  friendly = "" } // Parameter defaults
        );



        routes.MapRoute(
       "DownloadResume", // Route name
       "DownloadResume/", // URL with parameters
       new { controller = "Resume", action = "DownloadResume", id = UrlParameter.Optional } // Parameter defaults
        );
//Any of these
        routes.MapRoute(
        "cpe", // Route name
        "Play/CreatePlayEvent/{groupid}/{username}/{activeplay}/{game}", // URL with parameters
        new { controller = "Play", action = "CreatePlayEvent", groupID = "0", username = "", activeplay = "", game = "" } // Parameter defaults
     );

        routes.MapRoute(
           "CheckPlayEvent", // Route name
           "{controller}/{action}/{groupID}", // URL with parameters
           new { controller = "Play", action = "CheckPlayEvent", groupID = "0" } // Parameter defaults
        );

        routes.MapRoute(
           "clpe", // Route name
           "Play/ClearPlayEvent/{groupid}/{username}", // URL with parameters
           new { controller = "Play", action = "ClearPlayEvent", groupID = "0", username = "" } // Parameter defaults
        );

//结束损坏的路由routes.MapRoute(“默认”,//路由名称“ / / ”,//带参数new的URL {controller =“Blog”,action =“Index”, id = UrlParameter.Optional} //参数默认值);

myurl.com/Play/CheckPlayEvent/0

组ID在控制器端持续被视为NULL . 任何人?此外,似乎没有内置的调试器用于路由,或者至少我没有看到过 . 每个人都用什么调试路线?

有没有办法说控制器名称,方法名称和参数构成URL?

回答(1)

2 years ago

我认为以下路线受到打击,而不是您想要的路线:

routes.MapRoute(
     "ViewArticle", // Route name
     "{controller}/{action}/{id}/{friendly}", // URL with parameters
     new {  friendly = "" } // Parameter defaults
    );

友好是可选的,所以 {controller}/{action}/{id} 风格的路线也会出现这种情况 - 这看起来非常像你遇到麻烦的路线 .

将您的游戏路线移到此区域之上,然后重试 .