Syed Salman Raza Zaidi
Syed Salman Raza Zaidi

Reputation: 2192

MVC Redirect to another Controller In different namespace, but same project

I have differnt controllers in my Website, Some of them are in WebSite/Controller folder and some are in Website/Area/Test/Controllers.

When I hit Website/Controller/Home/Index, I want to redirect the user to Website/Area/Test/Controller/Home/Index with Query string PArameter.

Here's is my first Controller

namespace mySite.Controllers
{
 public partial class HomeController : BaseFrontController
    {
     public virtual ActionResult Index()
        {          
            var issuburl = channelRepository.GetChannelByUrl('UserID');
            if (issuburl != null)
                return Redirect("~/Areas/Test/Controllers/Index");

            return View();
        }
    }
}

and here's my Second Controller

namespace mySite.Areas.Test.Controllers
{
 public partial class HomeController : BaseTestController
    {
     public virtual ActionResult Index(string param)
        {          
            var chn = rep1.GetChannel(param);
            if (chn != null)
            {
                model.Chn = chn;
            }
            else return Redirect("~/Error/Index");      
            return View();
        }
    }
}

my Error Controller is in Mysite/Controller folder and I can access it inside MySite/Area/Test/Controller, but How can I access Mysite/Controller controller inside MySite/Area/Test/Controller

Below code is not working

return Redirect("~/Areas/Test/Controllers/Index");

Upvotes: 2

Views: 3354

Answers (2)

Marsh
Marsh

Reputation: 173

try this one:

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

Upvotes: 1

Satpal
Satpal

Reputation: 133403

Have you tried?

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

It is using RedirectToAction

To specify different parameters you can use

return RedirectToAction("Index", "controller", new { area = "Test", yourParam1 = "param1", yourParam2 = "param2" });

Upvotes: 4

Related Questions