使用ASP.NET MVC3中的路由在URL末尾添加查询字符串

Sna*_*yes 5 c# asp.net-mvc-3

我想使用路由将查询字符串添加到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)

Mar*_*ulz 8

生成操作URL时,可以传入其他路由值,如下所示:

@Url.Action("Detail", "MyController",
    new { id = 4, @ref = "test", other = "something" })
Run Code Online (Sandbox Code Playgroud)

未在路由的路由模板中定义的refother参数Detail将作为查询字符串参数附加.