在我开发的ASP.NET MVC(Beta)站点上,有时调用ActionLink会返回包含查询字符串的URL.我已经隔离了产生这种行为的情况,但我仍然不明白为什么,它不是生成一个干净的URL,而是决定使用查询字符串参数.我知道它们在功能上是相同的,但是为了URL的一致性(和外观),这不是我想要的.
这是我的路线:
routes.MapRoute( "Photo Gallery Shortcut", "group/{groupname}", new { controller = "Photos", action = "All", Id = "" }); routes.MapRoute( "Tagged Photos", //since the Tagged action takes an extra parameter, put it first "group/{groupname}/Photos/Tagged/{tagname}/{sortby}", new { controller = "Photos", action = "Tagged", Id = "", SortBy = "" }); routes.MapRoute( "Photo Gallery", //since the Gallery's defualt action is "All" not "Index" its listed seperatly "group/{groupname}/Photos/{action}/{sortby}", new { controller = "Photos", action = "All", Id = "", SortBy = "" }); routes.MapRoute( "Group", //<-- "Group" Category defined above "group/{groupname}/{controller}/{action}/{id}", new {controller = "Photos", action = "Index", Id = ""});
现在问题只发生在我查看名为"标记照片"的路径描述的视图并通过以下方式执行ActionLink时:
Html.ActionLink(p => p.All((string)ViewData["group"], ""), "Home")
哪个产生URL:
http://domain/group/GROUPNAME?sortBy=
从任何其他视图,生成的URL是:
http://domain/group/GROUPNAME
我已经删除了Phil的ASP.NET路由调试器,所有内容都按顺序显示.这个让我难过.有任何想法吗?