重定向到另一个控制器中的操作 [英] Redirect to Action in another controller
问题描述
我有两个控制器,都称为 AccountController
.其中一个,我们称之为Controller A
,位于一个名为Admin
的Area
中,另一个,我们称之为Controller B
,不在任何 Area
中(我猜这意味着它在默认的 Area
中?).Controller B
有一个名为 Login
的 action 方法
.我在 Controller A
中有一个 action 方法
,它有这一行
I have two controllers, both called AccountController
. One of them, lets call it Controller A
, is in an Area
called Admin
and the other, lets call it Controller B
, is not in any Area
(I guess that means it's in the default Area
?). Controller B
has an action method
called Login
. I have an action method
in Controller A
, which has this line
return RedirectToAction("LogIn", "Account");
问题是当这一行被执行时我得到一个 404
因为试图重定向到 Controller A<中不存在的
action
/代码>.我想调用Controller B
中的action method
.这可能吗?
The problem is that I get a 404
when this line gets executed because an attempt is made to redirect to a non-existent action
in Controller A
. I want to call the action method
in Controller B
. Is this possible?
推荐答案
您可以在 routeValues
参数中提供 area
.试试这个:
You can supply the area
in the routeValues
parameter. Try this:
return RedirectToAction("LogIn", "Account", new { area = "Admin" });
或
return RedirectToAction("LogIn", "Account", new { area = "" });
取决于您的目标区域.
这篇关于重定向到另一个控制器中的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!