Partial View

-> A partial view is like a user control in Asp.Net web form. Partial views are reusable views like Header and Footer. It has .cshtml extension.
-> There are different ways for rendering a partial view in MVC razor.

Html.RenderPartial
-> The method result will be directly written to the HTTP response stream means it uses the same TextWriter object used in current webpage/template.
-> Faster than Partial method since it is directly written to the response stream this makes it fast.
-> Simple to use and there is no need to create any action.
-> Returns void
-> RenderPartial method is useful when the displaying data in the partial view is already in the corresponding view model.For example : In a blog to show comments of an article, we would like to use RenderPartial method since an article information with comments are already populated in the view model.

Html.Partial
-> Renders the partial view as a HTML encoded string.
-> Simple to use and there is no need to create any action.
-> The method result can be stored in a variable, since it returns string type value.

Html.RenderAction
-> The method result will be directly written to the HTTP response stream mean it uses the same TextWriter object used in current webpage/template.
-> Need to create a child action for rendering the partial view.
-> Faster than Action method method since it is directly written to the response HTTP response stream this makes it fast.
-> RenderAction method is useful when the displaying data in the partial view is independent from corresponding view model.For example : In a blog to show category list on each and every page, we would like to use RenderAction method since the list of category is populated by the different model.

Html.Action
-> Renders the partial view as an HTML string.
-> The method result can be stored in a variable, since it returns string type value.

Leave a Reply

Your email address will not be published. Required fields are marked *