问题
When I'm in a View and I call @Html.RenderPartial("MyPartialView", MyObject)
Can I set it up so that this partial view has a controller which is called when RenderPartial gets called?
回答1:
Probably it will be better to use the RenderAction instead of the RenderPartial
回答2:
You should gather all data necessary for the partial in the current controller action (which may use methods shared across other controllers and actions).
If you really want a partial to be rendered using its own controller/action then consider loading it via AJAX with a separate request.
回答3:
In MVC, although controllers know about views, the reverse is not true.
Views are just means to render some data (a model or a viewModel) but they are not related to a controller or an action.
来源:https://stackoverflow.com/questions/6588571/asp-net-mvc-can-a-partial-view-have-a-controller