开发者

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

开发者 https://www.devze.com 2023-03-18 09:33 出处:网络
When I\'m in a View an开发者_JAVA技巧d 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?

When I'm in a View an开发者_JAVA技巧d 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?


Probably it will be better to use the RenderAction instead of the RenderPartial


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消