Let's assume I have 3 custom controllers: AController, BController and CControler and one default HomeController. Each of the first three controllers have a very unique partial view for them, let's name them APartial, BPartial, CPartial and these are invoked with AFunction, BFunction and CFunction with a template looking like:
public ActionResult XFunction
{
/*put some data into a ViewBag*/
return PartialView("XPartial");
}
Respectivelly, APartial.cshtml, BPartial.cshtml, CPartial.cshtml are in the Shared folder.
What is the best way to return all three views in one page when HomeController's Index (ActionResult method) is called. I tried rendering each like:
using (StringWriter sw = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, "XFunction");
ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
return MvcHtmlString.Create(sw.GetStringBuilder().ToString());
}
then putting each into ViewBag's dynamic variables, but I have a feeling there has to be a way nicer solution.
@Html.Partial, because I replace my main div with the result, so either: I cannot do that OR I overlooked being able to call@Html.Partialinside my Home/Index.cshtml. I am going to try that. I'll let you know asap.