首页 新闻 会员 周边

关于MVC4的出站路由的匹配规则

0
悬赏园豆:20 [待解决问题]

比如:我有一个路由表,

route.MapRoute("MyRoute","{controller}\{action}/{id}",new {controller="Home",action="Index",id=UrlParameter.Optional});

然后在view当中使用了这个出站路由:

<div>

@Html.ActionLink("this is  an outgoing URL","CustomeVariable");

</div>

此时的html变为:<a href="/Home/CustomeVariable">this is  an outgoing URL</a>

 

但是如果,添加一个路由,如:

route.MapRoute("NewRoute","{app/do{action}",new {controller="Home"});

route.MapRoute("MyRoute","{controller}\{action}/{id}",new {controller="Home",action="Index",id=UrlParameter.Optional});

此时的html变为:

<a href="app/doCustomeVariable">this is  an outgoing URL</a>

能不能讲讲这是为什么?

djlstrong的主页 djlstrong | 初学一级 | 园豆:122
提问于:2014-12-02 19:58
< >
分享
所有回答(2)
0

这不就是路由了。。。。。

吴瑞祥 | 园豆:29449 (高人七级) | 2014-12-02 21:41
0

你的@Html.ActionLink("this is  an outgoing URL","CustomeVariable");应该会匹配搭到route.MapRoute("NewRoute","{app/do{action}",new {controller="Home"})这个路由规则,但是你这个路由规则大括号不匹配不知道你哪漏写了。{app/do{action}里的app/do没有特殊含义就做字符串输出,而你的action是CustomeVariable所以有href="app/doCustomeVariable"。

Slark.NET | 园豆:692 (小虾三级) | 2014-12-02 22:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册