Helo, I try to have an URL like this /Forum/Index/2

for url I have a route {controller}/{action}/{page} in my global.asax

If i test the above url with the Route Debugger it corresponds to the above route ( and some other but this is the fist one in the list ) but if I create an url with the ActionLink ( like this : <%= Html.ActionLink(item.Title, "Index", new { controller = "Forum", page = page })%> ), this methode return me this URL /Forum/Index?page=2

Is there a way to a have an url with nothing in querystring with the ActionLink methode ?

This are all my routes and the match route is named DefaultWithPage :

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

        routes.MapRoute(
            "sitemapXML",
            "Sitemap.xml",                                                                                      // URL with parameters
            new { controller = "Sitemap", action = "Sitemap" }                                                  // Parameter defaults
        );

        routes.MapRoute(
            "ImageStat",                                                                                        // Route name
            "{controller}/{action}/{MailID}/{UserID}.gif",                                                      // URL with parameters
            new { controller = "", action = "", MailID = "", UserID = "" },                                     // Parameter defaults
            new { 
                MailID = @"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$", 
                UserID = @"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$" 
            }
        );

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

        routes.MapRoute(
            "DefaultWithPager",                                                                                 // Route name
            "{controller}/{action}/{page}",                                                                     // URL with parameters
            new { controller = "Home", action = "", page = "" },                                                // Parameter defaults
            new { page = @"^\d+$" }  
        );

        routes.MapRoute(
            "DefaultWithID",                                                                                    // Route name
            "{controller}/{action}/{ID}",                                                                       // URL with parameters
            new { controller = "Home", action = "", ID = "" },                                                  // Parameter defaults
            new { ID = @"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$" }
        );

        routes.MapRoute(
            "DetailWithID",                                                                                     // Route name
            "{controller}/{action}/{ID}/{Title}",                                                               // URL with parameters
            new { controller = "Home", action = "", ID = "", Title = "" },                                      // Parameter defaults
            new { ID = @"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$" }
        );

        //Handler route
        routes.MapRoute(
            "ImageResizer",                                                                                     // Route name
            "{controller}/{action}/{Title}/{ID}.jpg",                                                           // URL with parameters
            new { controller = "", action = "", Title = "", ID = "" }                                           // Parameter defaults
        );


        //Section Pages Routes
        routes.MapRoute(
            "SectionIndex",                                                                                     // Route name
            "{sectionName}/{controller}/{action}",                                                              // URL with parameters
            new { controller = "", action = "", sectionName = "" }                                              // Parameter defaults                
        );

        routes.MapRoute(
            "SectionDetails",                                                                                   // Route name
            "{sectionName}/{controller}/{action}/{ID}",                                                         // URL with parameters
            new { controller = "", action = "", sectionName = "", ID = "" }                                     // Parameter default
        );

        routes.MapRoute(
            "SectionDetailsWithDate",                                                                           // Route name
            "{sectionName}/{controller}/{action}/{month}/{year}",                                               // URL with parameters
            new { controller = "Home", action = "", page = "", month = "", year = "" },                         // Parameter defaults
            new { month = @"^\d+$", year = @"^\d+$" }
        );

        routes.MapRoute(
            "SectionDetailsWithTitle",                                                                          // Route name
            "{sectionName}/{controller}/{action}/{ID}/{Title}",                                                 // URL with parameters
            new { controller = "", action = "", sectionName = "", ID = "", Title = "" }                         // Parameter defaults
        );

        routes.MapRoute(
            "SectionDetailsPagingWithTitle",                                                                    // Route name
            "{sectionName}/{controller}/{action}/{page}/{ID}/{Title}",                                          // URL with parameters
            new { controller = "", action = "", sectionName = "", page = "", ID = "", Title = "" }              // Parameter defaults
        );

        routes.MapRoute(
            "SectionDetailsPaging",                                                                             // Route name
            "{sectionName}/{controller}/{action}/{page}/{ID}",                                                  // URL with parameters
            new { controller = "", action = "", sectionName = "", page = "", ID = "" }                          // Parameter defaults
        );

Gauthier

share|improve this question
Please post all route registrations. What you provide here should work just fine. – alexn Jan 17 '10 at 14:53
feedback

1 Answer

It sounds like your route registration is just fine. You just need to use the Html.RouteLink helper and tell it the name of the route to use:

<%= Html.RouteLink(item.Title, "DefaultWithPager", new { controller = "Forum", page = page })%>
share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.