Asp.net mvc 4 asp mvc友好url路由问题
我将下一个MapRoute添加到我的RouteConfig:Asp.net mvc 4 asp mvc友好url路由问题,asp.net-mvc-4,routes,Asp.net Mvc 4,Routes,我将下一个MapRoute添加到我的RouteConfig: routes.MapRoute( name: "Noticias", url: "{controller}/{action}/{id}/{urlAmiga}", defaults: new { controller = "Noticias", acti
routes.MapRoute(
name: "Noticias",
url: "{controller}/{action}/{id}/{urlAmiga}",
defaults: new
{
controller = "Noticias",
action = "Noticia",
id = "",
urlAmiga = ""
}
);
鉴于此,我有以下几点:
<a href="<%= Url.Action("Noticia","Noticias", new {id = item.IdNoticia, urlAmiga="this-is-a-test" }) %>">
<h5>
<%= item.Titulo %>
</h5>
</a>
我希望生成的链接如下所示:
但是,结果是:
为什么?确保在默认路线之前已声明此路线:
routes.MapRoute(
name: "Noticias",
url: "{controller}/{action}/{id}/{urlAmiga}",
defaults: new
{
controller = "Noticias",
action = "Noticia",
id = "",
urlAmiga = ""
}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}
);
显示所有路线。现在就像下面的答案一样,在我改变顺序之前继续,我把它移到了第一位,正如你所说的,但它还不起作用。我在RegisterRoutes方法中设置了一个断点,我可以看到它没有触发,我不知道是否可能与此有关。。。
routes.MapRoute(
name: "Noticias",
url: "{controller}/{action}/{id}/{urlAmiga}",
defaults: new
{
controller = "Noticias",
action = "Noticia",
id = "",
urlAmiga = ""
}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}
);