Asp.net mvc ASP.NET路由使用错误的路由生成URL;路由值成为查询字符串参数
有关路线登记号码:Asp.net mvc ASP.NET路由使用错误的路由生成URL;路由值成为查询字符串参数,asp.net-mvc,routing,Asp.net Mvc,Routing,有关路线登记号码: routes.MapRoute( "QuestionsMostRecent", "questions", new { controller = "questions", action = "most_recent" } ); routes.MapRoute( "ControllerActionFormat", "{controller}/{action}.{format}" ); Url.RouteUrl(new { controller =
routes.MapRoute(
"QuestionsMostRecent",
"questions",
new { controller = "questions", action = "most_recent" }
);
routes.MapRoute(
"ControllerActionFormat",
"{controller}/{action}.{format}"
);
Url.RouteUrl(new {
controller = "questions",
action = "most_recent",
format = "rss"
});
路由生成代码:
routes.MapRoute(
"QuestionsMostRecent",
"questions",
new { controller = "questions", action = "most_recent" }
);
routes.MapRoute(
"ControllerActionFormat",
"{controller}/{action}.{format}"
);
Url.RouteUrl(new {
controller = "questions",
action = "most_recent",
format = "rss"
});
我希望收到“/questions/most_-recent.rss”,但我收到的是“/questions?format=rss”。我意识到我可以通过引用路由名称“ControllerActionFormat”来强制实现我的预期结果,但我很好奇为什么路由系统与第一条路由完全匹配。有人能解释一下吗?因为两者都匹配,但首先注册的是定义更广泛的路由。首先注册更具体的路由,这将解决问题。因为两者都匹配,但首先注册的是定义更广泛的路由。首先注册更具体的路线,它将解决问题