2011-08-19 110 views
2

我有這樣的路由映射在Global.ascx:地圖自定義路由

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

因此,當用戶鍵入http://mysite.com/Help他會從Home.Help行動的響應。

但如果我嘗試調用該航線與參數id=somethinghttp://mysite.com/Help/something 我得到一個錯誤The resource cannot be found.

我怎麼能解決呢?

回答

5

您需要路由的URL模式中的{id}路由值令牌。

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