专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > ASP.NET

再发一个关于MVC 路由的有关问题

发布时间:2011-06-22 17:12:26 文章来源:www.iduyao.cn 采编人员:星星草
再发一个关于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
);

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: