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");
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?
This question is related to
asp.net-mvc
asp.net-mvc-3
c#-4.0
redirecttoaction
Use this:
return this.RedirectToAction<AccountController>(m => m.LogIn());
This should work
return RedirectToAction("actionName", "controllerName", null);
You can use this:
return RedirectToAction("actionName", "controllerName", new { area = "Admin" });
Try switching them:
return RedirectToAction("Account", "Login");
I tried it and it worked.
Use this:
return RedirectToAction("LogIn", "Account", new { area = "" });
This will redirect to the LogIn
action in the Account
controller in the "global" area.
It's using this RedirectToAction
overload:
protected internal RedirectToRouteResult RedirectToAction(
string actionName,
string controllerName,
Object routeValues
)
Source: Stackoverflow.com