RedirectToAction 位于区域之外

发布于 2024-09-08 07:48:52 字数 407 浏览 4 评论 0原文

我最近在工作中更新了我们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

も让我眼熟你 2024-09-15 07:48:52

看来我原来的解决方案:

return RedirectToAction("Index", "Home", new { area = "" });

确实有效。

我不确定我是如何设法让它以前不起作用,但现在它似乎按预期工作。

另外值得注意的是,即使代码工作正常,Visual Studio 2010 仍然告诉我无法解析操作“索引”

It seems that my origional solution:

return RedirectToAction("Index", "Home", new { area = "" });

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.

握住我的手 2024-09-15 07:48:52

尝试 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文