Returning Multiple partial views from single Controller action?

You can only return one value from a function so you can’t return multiple partials from one action method.
If you are trying to return two models to one view, create a view model that contains both of the models that you want to send, and make your view’s model the new ViewModel.
E.g.

Your view model would look like:

public class ChartAndListViewModel 
{
   public List<ChartItem> ChartItems {get; set;};
   public List<ListItem> ListItems {get; set;};
}

Then your controller action would be:

public ActionResult ChartList() 
{
   var model = new ChartAndListViewModel();
   model.ChartItems = _db.getChartItems();
   model.ListItems = _db.getListItems();

   return View(model);
}

And finally your view would be:

@model Application.ViewModels.ChartAndListViewModel

<h2>Blah</h2>

@Html.RenderPartial("ChartPartialName", model.ChartItems);

@Html.RenderPartial("ListPartialName", model.ListItems);

Leave a Comment