帮助asp.net路由

时间:2009-09-08 20:42:08

标签: asp.net-mvc

为什么会这样

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

    }

1 个答案:

答案 0 :(得分:2)

应该是:

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