2009-09-08 143 views
0

這是爲什麼幫助asp.net路由

<%=Html.ActionLink("Users", "Index", "Users", new { id = "3" })%> 

指向這個

http://localhost:1798/Users/Index?Length=8 

而是這個

http://localhost:1798/Users/Index/3 

註冊途徑方法:

public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

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

    } 
+0

是什麼在你的Global.asax您的RegisterRoutes方法樣子? – BigBlondeViking 2009-09-08 20:48:04

回答

2

它應該是:

<%= Html.ActionLink("Users", "Index", new {Id=3}) 
+1

這隻適用於在UsersController視圖中使用。否則它將不知道要調用哪個控制器。要強制它到控制器,使用'Html.ActionLink(「Users」,「Index」,「Users」,new {id = 3},null)' – aolde 2009-09-08 20:58:36