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?

4

1 回答 1

8

就这么简单:

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

您的 Controller 类名必须是 MainController 和 OtherOneController。如果您想更改它,请查看这篇文章: 更改 ASP.NET MVC 中的控制器名称约定

这是您的主控制器:

public class MainController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}
于 2013-07-29T15:37:13.080 回答