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

随声附和 提交于 2019-12-10 13:32:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!