ASP.NET MVC - Can a Partial View have a controller?

When I am in a view and I call @Html.RenderPartial("MyPartialView", MyObject) Can I configure it so that this partial view has a controller that gets called when RenderPartial is called?

+6
source share
3 answers

It is probably best to use RenderAction instead of RenderPartial

+8
source

You must collect all the data necessary for the partial controller in the current action (which can use methods shared by other controllers and actions).

If you really want the partial image to be displayed using your own controller / action, then consider loading it through AJAX with a separate request.

0
source

In MVC, although controllers are aware of representations, the opposite is not true.

Views are just a means to render some data (models or viewModel models), but they are not related to the controller or action.

0
source

Source: https://habr.com/ru/post/892071/


All Articles