Redirect to Action in another controller

前端 未结 5 594
暗喜
暗喜 2020-11-30 19:39

I have two controllers, both called AccountController. One of them, lets call it Controller A, is in an Area called Admin

相关标签:
5条回答
  • 2020-11-30 20:13

    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
    )
    

    MSDN

    0 讨论(0)
  • 2020-11-30 20:17

    You can supply the area in the routeValues parameter. Try this:

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

    Or

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

    depending on which area you're aiming for.

    0 讨论(0)
  • 2020-11-30 20:25

    Use this:

        return this.RedirectToAction<AccountController>(m => m.LogIn());
    
    0 讨论(0)
  • You can use this:

    return RedirectToAction("actionName", "controllerName", new { area = "Admin" });
    
    0 讨论(0)
  • 2020-11-30 20:37

    Try switching them:

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

    I tried it and it worked.

    0 讨论(0)
提交回复
热议问题