.NET MVC路由问题

时间:2014-03-13 00:23:00

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

出于某种原因,我的路线没有被.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(                 "默认",//路线名称                 " {controller} / {action} / {id}",//带参数的网址                 new {controller =" Blog",action =" Index",id = UrlParameter.Optional} //参数默认值             );

myurl.com/Play/CheckPlayEvent/0

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

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

1 个答案:

答案 0 :(得分:2)

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

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

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

将您的游戏路线移至上方,然后重试。