使用RedirectToAction方法时,Url Pattern丢失

时间:2011-09-07 17:40:40

标签: asp.net-mvc-3

我是MVC的新手,请查看以下案例:

global.asax中的规则;

routes.MapRoute(
"MonographContent", // Route name
"{controller}/{action}/{monographRevisionId}/{monographId}/{monographName}", // URL with parameters
new { controller = "Monographs", action = "MonographContent", monographRevisionId = String.Empty, monographId = String.Empty, monographName = String.Empty });

我的控制器;

public ActionResult MonographContent(string monographRevisionId, string monographId, string monographName)
{
  return View();
}

以下网址工作正常;

http://localhost/Monographs/MonographContent/v3/191b7a7e-a1bc-4602-b2bd-ac1193e07d25/MyMonograph

但是当我通过另一个动作方法重定向到相同的动作方法时,它会转换为QueryString

行动方法

public ActionResult Archive(string monographRevisionId, string monographId, string monographName)
{
return RedirectToAction("MonographContent", new System.Web.Routing.RouteValueDictionary(new { controller = "Monographs", action = "MonographContent", monographRevisionId = String.Empty, monographId = String.Empty, monographName = String.Empty }));
}

http://localhost/Monographs/MonographContent?monographRevisionId=v3&monographId=191b7a7e-a1bc-4602-b2bd-ac1193e07d25&monographName=MyMonograph

任何人都可以帮我修复它以保留网址格式。

由于

2 个答案:

答案 0 :(得分:2)

尝试直接通过路线重定向:

this.RedirectToRoute("MonographContent", new { monographRevisionId = String.Empty, monographId = String.Empty, monographName = String.Empty })});

答案 1 :(得分:0)

您只需发出正常的Redirect()电话:

return Redirect("/Monographs/MonographContent/");

特别基于您在示例中提供的RouteValueDictionary。