2009-09-08 182 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