Sac*_*nth 114 asp.net-mvc redirecttoaction c#-4.0 asp.net-mvc-3
我有两个控制器,都叫AccountController.其中一个,让我们调用它Controller A,在一个Area被调用Admin,另一个,让我们调用它Controller B,不在任何Area(我想这意味着它是在默认情况下Area?). Controller B有一个action method叫Login.我有一个action method在Controller A,它有这条线
return RedirectToAction("LogIn", "Account");
Run Code Online (Sandbox Code Playgroud)
问题是,404当这一行被执行时,我得到一个因为尝试重定向到不存在action的行Controller A.我想打电话给action method在Controller B.这可能吗?
Ror*_*san 224
您可以area在routeValues参数中提供.试试这个:
return RedirectToAction("LogIn", "Account", new { area = "Admin" });
Run Code Online (Sandbox Code Playgroud)
要么
return RedirectToAction("LogIn", "Account", new { area = "" });
Run Code Online (Sandbox Code Playgroud)
取决于您的目标区域.
gdo*_*ica 25
用这个:
return RedirectToAction("LogIn", "Account", new { area = "" });
Run Code Online (Sandbox Code Playgroud)
这将重定向到"全局"区域中控制器中的LogIn操作Account.
它正在使用这个RedirectToAction重载:
protected internal RedirectToRouteResult RedirectToAction(
string actionName,
string controllerName,
Object routeValues
)
Run Code Online (Sandbox Code Playgroud)
您可以使用此:
return RedirectToAction("actionName", "controllerName", new { area = "Admin" });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
236136 次 |
| 最近记录: |