1

このようなURLを取得しようとしています/Forum/Index/2

URLの場合、ルート{controller}/{action}/{page}がありますglobal.asax

Route Debugger を使用して上記の URL をテストすると、上記のルートに対応します (その他にもいくつかありますが、これはリストの最初のものです)。

しかし、ActionLink を使用して URL を作成すると (このように : <%= Html.ActionLink(item.Title, "Index", new { controller = "Forum", page = page })%>)、このメソッドはこの URL を返します/Forum/Index?page=2

ActionLink メソッドを使用してクエリ文字列に何もない URL を持つ方法はありますか?

これはすべて私のルートであり、一致するルートの名前は次のDefaultWithPagerとおりです。

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
);

ゴーティエ

4

2 に答える 2

4

ルート登録は問題ないようです。Html.RouteLink ヘルパーを使用して、使用するルートの名前を指定するだけです。

<%= Html.RouteLink(item.Title, "DefaultWithPager", new { controller = "Forum", page = page })%>
于 2010-01-18T02:46:45.733 に答える