ASP.NET MVC 路由和查询字符串
有人可以告诉我为什么,像这样的网址...
http://localhost:22220/groups/go/1234/2525?name=Bob
这个路由映射不匹配...
routes.MapRoute(null, // Route name
"groups/go/{groupId}/{userId}/{name}",
new { controller = "Groups", action = "Go" });
但是这个路由映射似乎匹配? (使用 Phil Haack 的路由测试器,这是“生成的 URL”)...
context.MapRoute("Teams_Default",
"Teams/{controller}/{action}/{id}",
new { id = UrlParameter.Optional });
Can someone please tell me why, with a url like this...
http://localhost:22220/groups/go/1234/2525?name=Bob
This route mapping doesn't match...
routes.MapRoute(null, // Route name
"groups/go/{groupId}/{userId}/{name}",
new { controller = "Groups", action = "Go" });
But this route mapping appears to match? (Using Phil Haack's Route Tester, this is the 'Generated URL')...
context.MapRoute("Teams_Default",
"Teams/{controller}/{action}/{id}",
new { id = UrlParameter.Optional });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该链接必须是:
http://localhost:22220/groups/go/1234/2525/Bob
或者您可以将路线更改为
“组/去/{groupId}/{userId}”
The link needs to be :
http://localhost:22220/groups/go/1234/2525/Bob
Or you could change the route to
"groups/go/{groupId}/{userId}"
由于该 URL 上最后一个“name”参数的格式不正确,因此第一个路由不会匹配。如果将路由更改为:
由于“名称”的默认值,它将起作用。
显然,这对您没有好处,因为您希望读取该名称。
我认为更大的问题是:该 URL 是如何生成的?
Since the last 'name' parameter is not formed correctly on that URL, the first route doesn't get matched. If you change the route to this:
it will work because of the default value for 'name'.
Obviously, this is no good for you since you want the name to be read.
I think the bigger question is: How is that URL being generated?