RedirectToAction outside of Areas
Asked Answered
P

2

12

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 });
Payment answered 8/7, 2010 at 11:31 Comment(2)
Its mean you want to move to new URL , Outside the controller ? M i getting right?Garrard
I want to redirect to an action which is outside the current Area.Payment
P
30

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.

Payment answered 8/7, 2010 at 12:56 Comment(1)
return RedirectToAction("Index", "Home", new { area = "" }); Thanks, it's work for me.Rafaelarafaelia
S
0

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.

Sweettempered answered 8/7, 2010 at 11:56 Comment(3)
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.Payment
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.Sweettempered
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.Payment

© 2022 - 2024 — McMap. All rights reserved.