Url Pattern lost while using RedirectToAction method
I am new in MVC, please review the following case:
Rule in 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 });
My Controller;
public ActionResult MonographContent(string monographRevisionId, string monographId, string monographName)
{
return View();
}
Following url works fine;
http://localhost/Monographs/MonographContent/v3/191b7a7e-a1bc-4602-b2bd-ac1193e07d25/MyMonograph
But when I redirects to the same action method through another action method it converts into QueryString
Action Method
public ActionResult Archive(string monographRevisionId, string monographId, string monographName)
{
return RedirectToAction("MonographContent", new System.Web.Routing.RouteValueDictionary(new { controller = "Monographs", action = "Mo开发者_如何学CnographContent", monographRevisionId = String.Empty, monographId = String.Empty, monographName = String.Empty }));
}
http://localhost/Monographs/MonographContent?monographRevisionId=v3&monographId=191b7a7e-a1bc-4602-b2bd-ac1193e07d25&monographName=MyMonograph
Can anyone help me how to fix it to preserve the url pattern.
Thanks
Try to redirect directly by route:
this.RedirectToRoute("MonographContent", new { monographRevisionId = String.Empty, monographId = String.Empty, monographName = String.Empty })});
You should simply issue a normal Redirect()
call:
return Redirect("/Monographs/MonographContent/");
Particularly based on the RouteValueDictionary you provided in your example.
精彩评论