tags:

views:

48

answers:

2

I have a situation where I want to render the content from a different controller & action.

I do not want to redirect the user to a different URL, I just want to wire up the controller, pass it the info it needs, and have it return the correct view. I want it to think that it was supposed to be there, in that particular url where its called.

How can this be done?

A: 

Return the following.

return View("ViewName");

You then need to put "ViewName.aspx" in the Shared folder, since the view is now shared by multiple controllers.

Jarrett Meyer
+2  A: 

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();
    }
}
jayrdub