开发者

calling a partial view in asp.net MVC3

开发者 https://www.devze.com 2023-02-23 08:04 出处:网络
What 开发者_JS百科is difference between Html.Partial and Html.action in context of using a partial view in asp.net MVC3 ?Html.Action will call a controller Action, so it\'ll go through the whole MVC p

What 开发者_JS百科is difference between Html.Partial and Html.action in context of using a partial view in asp.net MVC3 ?


Html.Action will call a controller Action, so it'll go through the whole MVC pipeline (inside the server) again to find a controller that will return a ViewResult (although, you theoretically you can also return a JsonResult or something else) .

Html.Partial will only return a PartialPage (as in a CSHTML file) and won't go through the whole pipeline. It will just search using the view engine.

Some advantages to Action is having Authentication, Caching and other stuff that happens in the MVC pipeline, while Partial is faster (although you might have more responsibility in the partial page if you need to pass a ViewModel etc.)

This is a nice post (a bit old) about pros/cons of RenderAction vs RenderPartial


Html.Partial includes directly the view at the place where you called the helper. It is like a file include.

Html.Action invokes a controller action first which could render a view and it is the result of this action that is included. And because a controller action is invoked a controller needs to be instantiated, so the whole MVC pipeline gets executed as a child request.

You may take a look at the following blog post.


Stackoverflow ninja search got me this:

Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

Also see this article Render Action vs RenderPartial

0

精彩评论

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