我想使用路由将查询字符串添加到url的末尾。如何在Global.asax中执行此操作?
routes.MapRoute(
"Detail",
"{controller}/{action}/{id}/{name}",
new
{
action = "Detail",
name = UrlParameter.Optional,
// it is possible to add here query string(s) ?
},
new[] { "MyProject.Controllers" }
);
例如,实际的URL包含:
www.mysite.com/MyController/Detail/4/MyValue
但我想生成类似的东西:
www.mysite.com/MyController/Detail/4/MyValue?ref=test&other=something
最佳答案
生成操作URL时,您可以传递其他路由值,如下所示:
@Url.Action("Detail", "MyController",
new { id = 4, @ref = "test", other = "something" })
在
ref
路由的路由模板中未定义的other
和Detail
参数将附加为查询字符串参数。