2

In my project I have two different controllers.
This is the main one:

public class Main : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

And this is the other one:

public class OtherOne : Controller
{
    public ActionResult RandomAction()
    {
        return ... //more code here
    }
}

What should I return in "OtherOne/RandomAction" in order to obtain the same result of "Main/Index" action?

tereško
  • 58,060
  • 25
  • 98
  • 150
xnr_z
  • 1,161
  • 2
  • 18
  • 34
  • 1
    What are you trying to achieve? What do you mean by same result like "Main/Index". If both action methods have the same logic, why do you have two actions? Simplest way is to use RedirectToAction and store the data in TempData collection which can be accessed in the Main/Index. – Nilesh Jul 29 '13 at 15:40

1 Answers1

8

It's as simple as this:

public class OtherOneController : Controller
{
    public ActionResult RandomAction()
    {
        return RedirectToAction("Index", "Main");
    }
}

Your Controller class names must be MainController and OtherOneController. If you want to change that, check this post: change controller name convention in ASP.NET MVC

Here is your Main Controller:

public class MainController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}
Community
  • 1
  • 1
ataravati
  • 8,891
  • 9
  • 57
  • 89