Posted By : Murugan Andezuthu Dharmaratnam
Posted On : 22 January 2015
Keywords : Partial View, MVC Partial View, ASP .NET MVC Partial View, ASP .NET, MVC

MVC Partial View


A partial view enables you to define a view that will be rendered inside a parent view. Partial views are implemented as ASP.NET user controls.When a partial view is instantiated, it gets its own copy of the ViewDataDictionary object that is available to the parent view. The partial view therefore has access to the data of the parent view. However, if the partial view updates the data, those updates affect only the partial view's ViewData object. The parent view's data is not changed.By using partial view we can render a view inside a parental view and to create reusable content in the project.

How To Create A Partial View


Creating partial view can be explained by the following simple steps.

Step 1: Open our Application and open the 'View' folder in solution explorer.

Step 2: Right click on the 'Shared' folder in 'View',then Add->View.



Step 3: Give a name to our partial view,also click on the check box 'Create a partial view'.



Step 4: Now we create a Partial View with .cshtml extension for our application.

Partial View Rendering


A partial view is rendered by using the ViewUserControl class. Different methods such as Partial, RenderPartial, RenderAction helper are used to render partial view. Examples are shown below.

Using Partial Method
Using RenderPartial Method:

There is a difference between above 2 methods,ie the Patial helper method renders a partial view into a striing while RenderPartial method writes directly into the response stream instead of returning a string.


Using RenderAction Method:

This method is used when some information is need to show on multiple pages.

Using JQuery:

In some cases we need to load a partial view with in a popup in this situation we use JQuery.

Differece Between View And Partial View


View contains the layout page.Before any view is rendered,viewstart page is rendered.View have markup tags.If there is no layout page specified in the view, it can be considered as a partial view.

Partial view is more lightweight than the view.The Partial view is specially designed to render within the view and as a result it does not contain any mark up.Partial view does not contain the layout page


Murugan Andezuthu Dharmaratnam

Murugan is a technology leader with 14 years of hands-on experience in full life cycle systems design, development, implementation, and management. In addition to systems design and development, his core competencies include cloud design and architecture, interactive web applications and websites development, mobile computing, and Healthcare Information Technology. His experience is very diverse with a broad range of technologies within multiple industry settings including private, public, and non-profit. Coupled with his technology expertise, Murugan is a well-organized, result-oriented, and a highly analytical leader with proven track record in developing and implementing very complex systems.