Difference between Render Partial and Render Action

1

I'd like some help to better understand these types of partial view rendering.

    
asked by anonymous 05.03.2016 / 16:38

1 answer

3

Html.RenderAction

  • This method result will be written directly to the HTTP response stream response stream used. It means that the same object used as TextWriter will also be used for the page and / or template.

  • For this method, you need to create a child action to render the partial view.

  • The RenderAction method is useful when the data that is used in the partial view is identical to the corresponding view model. Example: In a blog to display list of categories on each page, we would like to use the RenderAction method since the list of category would be populated by a different model.

    @ {Html.RenderAction ("Category", "Home");}

  • This method is the best choice when you want to cache the view a partial view.

  • This method is faster than a simple Action call for example, since the response is also used directly via HTTP response stream, leaving the response faster.

Html.RenderPartial

  • This method result will be written directly to the HTTP response stream response stream used. It means that the same object used as TextWriter will also be used for the page and / or template.
  • This method "returns" void.
  • Simple to use and no need to create an action.
  • The RenderPartial Method is useful when the partial view view data is already view model. For example: In a blog, to show the comments of an article, we would like to use the RenderPartial method since the article with the comments have already been filled in the view model.

    @ {Html.RenderPartial ("_ Comments");}

Full Source: link

    
05.03.2016 / 16:51