开发者

ASP.NET MVC Routing and QueryStrings

开发者 https://www.devze.com 2023-03-08 07:49 出处:网络
Can someone please tell me why, with a url like this... 开发者_运维百科 http://localhost:22220/groups/go/1234/2525?name=Bob

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 });


The link needs to be : http://localhost:22220/groups/go/1234/2525/Bob

Or you could change the route to "groups/go/{groupId}/{userId}"


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:

routes.MapRoute(null, // Route name
                "groups/go/{groupId}/{userId}/{name}",
                new { controller = "Groups", action = "Go", name = "Bob" });

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消