I need to update Multiple from an Ajax call , I am confused as in how to return these Multiple views from the Controller Action method.
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.
In ASP.NET Core MVC, a controller's ViewResult is capable of returning either a view or a partial view. In Razor Pages, a PageModel can return a partial view represented as a PartialViewResult object. Referencing and rendering partial views is described in the Reference a partial view section.
Yes You can use multiple View in one Controller.
To return a Partial view from the controller action method, we can write return type as PartialViewResult and return using PartialView method.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With