日期:2014-05-20  浏览次数:20390 次

再发一个关于MVC 路由的问题
路由定义如下:
 context.MapRoute(
  "Lottery_shuyuDetail",
  "Lotteryshuyu/{action}-{type}-{id}.html",
  new { controller = "LotteryShuyu", action = "ShuyuDetail", type = "ssq", id = 234 },
  controllerNamespaces
  );

  context.MapRoute(
  "Lottery_shuyulist",
  "Lotteryshuyu/{action}-{type}.html",
  new { controller = "LotteryShuyu", action = "ShuyuList", type = "ssq" },
  controllerNamespaces
  );

我在页面里使用
 <%= Html.ActionLink("我的链接", "ShuyuList", new { type = "dlt" })%>

从生成的链接看:http://localhost:62/Lotteryshuyu/ShuyuList-dlt-234.html

是进入了第一个路由,但是我想让它近第二个路由呀。我哪里错了?
如果我把两个路由颠倒,这个链接是对了,但是另外一个的又错了。

我如何弄呢?

------解决方案--------------------
加限制条件试试看,可能是第一个ID没有,但是默认也算比对成功。new { id=@"\d+"},这样限制路由的id必须是数字才能比对成功。
 context.MapRoute(
"Lottery_shuyuDetail",
"Lotteryshuyu/{action}-{type}-{id}.html",
new { controller = "LotteryShuyu", action = "ShuyuDetail", type = "ssq", id = 234 },
new { id=@"\d+"},
controllerNamespaces
);