ASP MVC ReidrectToRoute没有查询字符串

时间:2015-09-03 13:08:29

标签: asp.net-mvc asp.net-mvc-routing asp.net-routing

我在Controller中使用此代码RedirectToRoute

return RedirectToRoute(new
            {
                controller = "Posts",
                action = "Post",
                parametr1 = "11",
                parametr2 = "aaaaaaaa"
            });

url输出是这样的:

https://localhost:45303/Posts/Post?parametr1=11&parametr2=aaaaaa

但我希望url输出没有这样的查询字符串:

https://localhost:45303/Posts/Post/1/aaaaaa

这是我的路线:

  routes.MapRoute(
           name: "Default1",
           url: "{controller}/{action}/{parametr1}/{parametr2}/{parametr3}",
           defaults: new { controller = "Home", action = "Index", parametr1 = UrlParameter.Optional, parametr2 = UrlParameter.Optional, parametr3 = UrlParameter.Optional }
       );

怎么办呢? 我使用RedirectToRouteRedirectToAction,但结果相同。

1 个答案:

答案 0 :(得分:1)

RedirectToRoute使用此重载并提供正确的路由名称:

return RedirectToRoute("Default1", new
        {
            controller = "Posts",
            action = "Post",
            parametr1 = "11",
            parametr2 = "aaaaaaaa"
        });