We have got two controllers:
HomeController
ExampleController
HomeController has a view, lets say Index, which as a model has Home model.
ExampleController has a method, which takes id (obtained from Home model) as a parameter, and returns a partial view _examplePartial with a model of a list Example models.
In a Index view of HomeController, i need to show this partial, but it need to be filled with data from ExampleController.
Is it possible to do that?
@Html.RenderAction – doesn’t work
@Html.Partial – of course also doesn’t work
2
Answers
In your ExampleController, you would need to modify the ExampleAction method to accept the "id" parameter and use it to populate the list of Example models that will be passed to the partial view. The partial view can then be returned using the PartialView method:
With these changes, the Html.Action method should now render the _examplePartial view with the list of Example models obtained from ExampleController.
@Html.RenderAction would work for your requirement in asp.net
It seems you are trying with a .net core MVC app, you’d better modify the tag(remove asp.net related tag)
I tried with two solutions for your requirement in default asp.net core app:
Load partial view with jquery codes:
Controllers:
View:
Index
Partial:
ViewComponent Solution:
In privacy page called:
Structure:
Result: