重定向到行动中另一个控制器 [英] Redirect to Action in another controller

查看:120
本文介绍了重定向到行动中另一个控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个控制器,这两个名为的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆