6

What is difference between Html.Partial and Html.action in context of using a partial view in asp.net MVC3 ?

gideon
  • 19,329
  • 11
  • 72
  • 113
DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

2 Answers2

10

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

Linkgoron
  • 4,866
  • 2
  • 26
  • 26
4

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928