路由定义如下:
context.MapRoute(
"Lottery_shuyuDetail",
"Lotteryshuyu/{action}-{type}-{id}",
new { controller = "LotteryShuyu", action = "ShuyuDetail", type = "ssq", id = 234 },
controllerNamespaces
);
context.MapRoute(
"Lottery_shuyulist",
"Lotteryshuyu/{action}-{type}",
new { controller = "LotteryShuyu", action = "ShuyuList", type = "ssq" },
controllerNamespaces
);
我在页面里使用
<%= Html.ActionLink("我的链接", "ShuyuList", new { type = "dlt" })%>
从生成的链接看:http://localhost:62/Lotteryshuyu/ShuyuList-dlt-234
是进入了第一个路由,但是我想让它近第二个路由呀。我哪里错了?
如果我把两个路由颠倒,这个链接是对了,但是另外一个的又错了。
我如何弄呢?
------解决方案--------------------------------------------------------
加限制条件试试看,可能是第一个ID没有,但是默认也算比对成功。new { id=@"\d+"},这样限制路由的id必须是数字才能比对成功。
context.MapRoute(
"Lottery_shuyuDetail",
"Lotteryshuyu/{action}-{type}-{id}",
new { controller = "LotteryShuyu", action = "ShuyuDetail", type = "ssq", id = 234 },
new { id=@"\d+"},
controllerNamespaces
);