How do I manually hook up an MVC controller and force it to perform an action?
I have a situation where I want to display content from another controller and action.
I don't want to redirect the user to a different url, I just want to connect the controller, pass it the information it needs, and return it the correct view. I want it to think that it should have been there, in that particular url where it was called.
How can I do that?
+2
Ryan M
source
to share
2 answers
I believe you can do this ...
public class FirstController : Controller
{
public ActionResult Index()
{
return View("~/Views/First/Index.aspx");
}
}
public class SecondController : Controller
{
public ActionResult Index()
{
return new FirstController().Index();
}
}
+4
JeremyWeir
source
to share
Return the following.
return View("ViewName");
Then you need to put "ViewName.aspx" in the public folder as the view is now shared by multiple controllers.
0
Jarrett Meyer
source
to share