Redirect to action in another controller

I have two controllers called AccountController . One of them, let's call it Controller A , is located in an Area called Admin , and the other one allows us to call it Controller B , is not in any Area (I think it means it is Area by default). Controller B has an action method called Login . I have an action method in Controller A that has this line

 return RedirectToAction("LogIn", "Account"); 

The problem is that I get 404 when this line is executed, because an attempt is being made to redirect to a nonexistent action in Controller A I want to call the action method in Controller B Is it possible?

+83
asp.net-mvc asp.net-mvc-3 redirecttoaction
May 28 '12 at 1:11
source share
2 answers

You can specify area in the routeValues parameter. Try the following:

 return RedirectToAction("LogIn", "Account", new { area = "Admin" }); 

or

 return RedirectToAction("LogIn", "Account", new { area = "" }); 

depending on which area you are striving for.

+162
May 28 '12 at 1:13 p.m.
source share

Use this:

 return RedirectToAction("LogIn", "Account", new { area = "" }); 

This will be redirected to the LogIn action in the Account controller in the "global" area.

It uses this RedirectToAction overload:

 protected internal RedirectToRouteResult RedirectToAction( string actionName, string controllerName, Object routeValues ) 

MSDN

+16
May 28 '12 at 13:15
source share



All Articles