我想使用路由将查询字符串添加到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" }
);
Run Code Online (Sandbox Code Playgroud)
例如,实际网址包含:
www.mysite.com/MyController/Detail/4/MyValue
Run Code Online (Sandbox Code Playgroud)
但我想生成类似的东西:
www.mysite.com/MyController/Detail/4/MyValue?ref=test&other=something
Run Code Online (Sandbox Code Playgroud)
生成操作URL时,可以传入其他路由值,如下所示:
@Url.Action("Detail", "MyController",
new { id = 4, @ref = "test", other = "something" })
Run Code Online (Sandbox Code Playgroud)
未在路由的路由模板中定义的ref和other参数Detail将作为查询字符串参数附加.
| 归档时间: |
|
| 查看次数: |
15616 次 |
| 最近记录: |