RedirectToRoutePermanent 不接受 Action 作为参数
我想这样做:
return RedirectToRoutePermanent("Dealers", new { action = "Join" });
但相反,我必须这样做才能使其工作:
return RedirectPermanent("/dealers/join");
加入是经销商控制器中的一个操作,而另一条路线可以很好地路由到经销商控制器。但是当我尝试这种方式时,会出现错误,找不到路线。有什么想法吗?
I'd like to do this:
return RedirectToRoutePermanent("Dealers", new { action = "Join" });
but instead I had to do this to make it work:
return RedirectPermanent("/dealers/join");
Join is an action in the Dealers controller, and another route works fine with being routed to the Dealers controller. But when I try things this way, it errors with no route found. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 MSDN 参考,ReidrectToRoutePermanent 采用一个字符串参数,该参数应该是路由名称而不是控制器名称。如果您依靠默认路由导航到 /dealers/join 那么这将不起作用。您的路由表是什么样的?可以附上注册路线代码吗?此外,我认为您需要一种方法 RedirectToActionPermanent 如果您在控制器操作方法范围内执行。
Based on the MSDN reference, the ReidrectToRoutePermanent takes a string parameter which should be the route name and not controller name. If you rely on the default route to navigate to /dealers/join then this will not work. What does your routing table look like? Can you attach the Register Routes code? Furthermore, I think you want a method RedirectToActionPermanent if you're executing within Controller action method scope.
可能有更好的方法,但您可以在调用中将 Url.Action() 包含到您的方法中吗?
There may be a better way but can you just include Url.Action() to your method in the call?
您可以使用 RedirectToRoutePermanent。
RedirectToRoutePermanent 方法与 RouteName 一起使用。
因此,您需要将 RouteName 作为第一个参数传递,将 Route 参数作为第二个参数传递。
此外,您还需要提及控制器名称。
比如,
希望有帮助。
You can use RedirectToRoutePermanent.
RedirectToRoutePermanent method works with RouteName.
So, you need to pass your RouteName as first parameter and Route parameters as second parameter.
Also, you need to mention controller name as well.
Something like,
Hope helps.