RedirectToRoutePermanent 不接受 Action 作为参数

发布于 2024-12-20 01:12:05 字数 282 浏览 2 评论 0原文

我想这样做:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧夏天 2024-12-27 01:12:05
return RedirectToActionPermanent("Join", "Dealers");
return RedirectToActionPermanent("Join", "Dealers");
不奢求什么 2024-12-27 01:12:05

根据 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.

是你 2024-12-27 01:12:05

可能有更好的方法,但您可以在调用中将 Url.Action() 包含到您的方法中吗?

There may be a better way but can you just include Url.Action() to your method in the call?

做个ˇ局外人 2024-12-27 01:12:05

您可以使用 RedirectToRoutePermanent。
RedirectToRoutePermanent 方法与 RouteName 一起使用。
因此,您需要将 RouteName 作为第一个参数传递,将 Route 参数作为第二个参数传递。

此外,您还需要提及控制器名称。
比如,

return RedirectToRoutePermanent("YourRouteName", new { controller="Dealers", action = "Join" });

希望有帮助。

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,

return RedirectToRoutePermanent("YourRouteName", new { controller="Dealers", action = "Join" });

Hope helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文