I use the RedirectToAction with parameters in my action method
return RedirectToAction("ListThreads", "View", new { category = "1", subcategory = "49"});
After redirect the url comes out like this http://domain/Forum/View/ListThreads?category=1&subcategory=49
I want it to be generated like http://domain/Forum/View/ListThreads/1/49
How to do it?
Note : I already have a route in global.asax that is used by all the pages/links.
context.MapRoute(
"Forum_subcategory",
"Forum/{controller}/{action}/{category}/{subcategory}",
new { controller = "View", action = "ListThreads"开发者_StackOverflow社区, category = "", subcategory = "" }
);
I had a simular problem with routing in my application, to fix my problem I used: RedirectToRoute. If you change your RedirectToAction to this:
return RedirectToRoute("Forum_subcategory", new { controller = "View", action = "ListThreads", category = "1", subcategory = "49" });
You should get the result you are looking for. For more information the Controller.RedirectToRoute Method refer to: http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoroute(v=vs.98).aspx
I've seen similar issues before. As crap as it sounds, you might have to wrap your object in a RouteValueDictionary
:
return RedirectToAction("ListThreads", "View", new RouteValueDictionary(new { category = "1", subcategory = "49"}));
Give it a try, see how it goes.
精彩评论