RedirectToAction outside of Areas

隐身守侯 提交于 2019-12-08 16:39:13

问题


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 });

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3203062/redirecttoaction-outside-of-areas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!