一般页面是有不带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 这样的链接 说明只匹配了第一条的路由,没匹配到下面那个。请问 怎么让他 匹配到下面的那个?应该是第一个写的有问题。 这两条路由调换顺序也不对
<%:Html.RouteLink("tessd","Default",new {action="Test",id = "33" })%> //Test action
"Default", // 路由名称
"{controller}/{action}/{id}.html", // 带有参数的 URL
new { controller = "Home", action = "Index", id = "1" } // 参数默认值
);放到前面了 然后去掉 把那个红的去掉。因为有默认值 所以在原来的那种顺序下,总是匹配这个 因为有默认值 ,去掉默认值就不匹配了。