重定向到行动中另一个控制器 [英] Redirect to Action in another controller
问题描述
我有两个控制器,这两个名为的AccountController
。其中之一,让我们把它叫做控制器A
,是一个区
名为管理
及其他,让我们把它叫做控制器B
,是不以任何区
(我猜意味着它在默认的区
?)。 控制器B
有一个操作方式
名为登录
。我在控制器A
,里面有该行的操作方式
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
时,因为试图重定向到一个不存在的动作这一行被执行
在控制器A
。我想打电话给在的
。这可能吗?操作方式
控制器B
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
区域 >参数。试试这个:
You can supply the area
in the routeValues
parameter. Try this:
return RedirectToAction("LogIn", "Account", new { area = "Admin" });
或者
return RedirectToAction("LogIn", "Account", new { area = "" });
这取决于你的目标的区域。
depending on which area you're aiming for.
这篇关于重定向到行动中另一个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!