一般页面是有不带ID,如Index.html
     routes.MapRoute(
           "Globel", // 路由名称
            "{controller}/{action}.html", // 带有参数的 URL
            new { controller = "Home", action = "Index" } // 参数默认值
            );
    还有一种是带参数的如Home/Index/33.html
    routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}.html", // 带有参数的 URL
                new { controller = "Home", action = "Index", id = "1" } // 参数默认值
    ); 这种顺序的情况下,如果是   <%:Html.ActionLink("test", "Test", new { id="33"})%>就会自动生成 Index.html?id=33 这样的链接 说明只匹配了第一条的路由,没匹配到下面那个。请问 怎么让他 匹配到下面的那个?应该是第一个写的有问题。 这两条路由调换顺序也不对

解决方案 »

  1.   

    没看出问题,把扩展名改成别的试试,比如 .mvc
      

  2.   

     <%:Html.ActionLink("test", "Test", new { id="33"})%>Index.html?id=33这个奇怪,即使不匹配,也应该是 Test.html?id=33
      

  3.   

    那你 就 指定 route 来显示, //<%:Html.ActionLink("test", "Test", new { id = "33" })%>
     <%:Html.RouteLink("tessd","Default",new {action="Test",id = "33" })%>  //Test action
      

  4.   

    解决了 我把有ID的 routes.MapRoute(
                    "Default", // 路由名称
                    "{controller}/{action}/{id}.html", // 带有参数的 URL
                    new { controller = "Home", action = "Index", id = "1" } // 参数默认值
        );放到前面了 然后去掉 把那个红的去掉。因为有默认值 所以在原来的那种顺序下,总是匹配这个 因为有默认值 ,去掉默认值就不匹配了。