RedirectToAction 位于区域之外
我最近在工作中更新了我们的 MVC 2 项目以使用 Areas,但是我在使用 RedirectToAction
方法时遇到了一些问题。
我们的一些管制员等仍然位于我们的区域之外。这些控制器包括主控制器等。
如何从区域内部到区域外部的控制器执行RedirectToAction
。
我认为像下面这样的东西可能会起作用,但不起作用:
return RedirectToAction("Index", "Home", new { area = "" });
或者
return RedirectToAction("Index", "Home", new { area = null });
I've recently updated our MVC 2 project at work to use Areas however I'm having a little problem with the RedirectToAction
method.
We still have some of our controllers etc outside of our Areas. These controllers include the Home controller etc.
How do I do a RedirectToAction
from inside an Area to a controller outside of Areas.
I thought something like the following might work but doesn't:
return RedirectToAction("Index", "Home", new { area = "" });
or
return RedirectToAction("Index", "Home", new { area = null });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来我原来的解决方案:
确实有效。
我不确定我是如何设法让它以前不起作用,但现在它似乎按预期工作。
另外值得注意的是,即使代码工作正常,Visual Studio 2010 仍然告诉我
无法解析操作“索引”
。It seems that my origional solution:
does infact work.
I'm not sure how I was managing to make it not work before but it seems to be working as expected now.
Also worth noting that Visual Studio 2010 still tells me that
Cannot resolve action 'Index'
even though the code works fine.尝试
return RedirectToAction("Index", "Home", new {area = Nothing});
擦洗上面的内容...
查看此 链接在这里。基本上,我认为您最初是在视图中尝试执行此操作,而不是在控制器操作中执行此操作。由于我看到这是一个控制器操作,因此您必须使用
RedirectToRoute
从当前区域进行更改。Try
return RedirectToAction("Index", "Home", new {area = Nothing});
Scrub the above...
Check out this link here. Basically I thought you were trying to do this in a View initially and not a controller action. Since I see that it is a controller action, you have to use
RedirectToRoute
to change from your current area.