views:

36

answers:

2

Hey everyone,

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

A: 

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.

Tommy
I think Nothing is a VB.NET thing. I'm using C#. I tried it anyway just to be sure but yeah, it doesn't work.
Jamie Dixon
Indeed it is, guess that C# tag should have alerted me to a different language :) anyways, found some additional info for you to check out.
Tommy
Thanks for your help Tommy. I did try out the RedirectToRoutes thing after finding it on Google and it does work! I've also discovered that my question is a bit null-and-void since my RedirectToAction code started to work...I must have done something silly to stop it working but i'm unsure what.
Jamie Dixon
A: 

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.

Jamie Dixon