我在Controller中使用此代码RedirectToRoute
return RedirectToRoute(new
{
controller = "Posts",
action = "Post",
parametr1 = "11",
parametr2 = "aaaaaaaa"
});
url输出是这样的:
https://localhost:45303/Posts/Post?parametr1=11¶metr2=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 }
);
怎么办呢?
我使用RedirectToRoute
和RedirectToAction
,但结果相同。
答案 0 :(得分:1)
对RedirectToRoute使用此重载并提供正确的路由名称:
return RedirectToRoute("Default1", new
{
controller = "Posts",
action = "Post",
parametr1 = "11",
parametr2 = "aaaaaaaa"
});