将自定义路由与 RedirectToAction (asp.net mvc) 一起使用
我在操作方法中使用带参数的 RedirectToAction
return RedirectToAction("ListThreads", "View", new { category = "1", subcategory = "49"});
重定向后,网址如下所示 http://domain/Forum/View/ListThreads?category=1&subcategory=49
我希望它像这样生成 http://domain/Forum/View/ListThreads/1/49
如何操作?
注意:我已经在 global.asax 中有一条由所有页面/链接使用的路线。
context.MapRoute(
"Forum_subcategory",
"Forum/{controller}/{action}/{category}/{subcategory}",
new { controller = "View", action = "ListThreads", category = "", subcategory = "" }
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在应用程序中遇到了类似的路由问题,为了解决我的问题,我使用了:RedirectToRoute。如果您将 RedirectToAction 更改为:
您应该得到您正在寻找的结果。有关 Controller.RedirectToRoute 方法的详细信息,请参阅:http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoroute(v=vs.98).aspx
I had a simular problem with routing in my application, to fix my problem I used: RedirectToRoute. If you change your RedirectToAction to this:
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
我以前见过类似的问题。尽管听起来很糟糕,但您可能必须将对象包装在 RouteValueDictionary 中:
尝试一下,看看效果如何。
I've seen similar issues before. As crap as it sounds, you might have to wrap your object in a
RouteValueDictionary
:Give it a try, see how it goes.