Partial View in ASP.NET MVC like a User Control in ASP.NET Web Forms. In order to reuse a View in our MVC application (For example, use a header, list of items or footer etc.), Partial Views are introduced that basically renders inside a Parent View.
Let’s give an example to understand the concept of Partial Views in more simple and better way. Consider we have list of our company products being displayed on Products page of our website. Now, we want to have another web page “Search Product” where we need to display the list of products in same manner but filtered according to a search criteria.
Now, In order to display list of products on “Search Product” page, we have two options:
1. Rewrite all HTML and Code for displaying product list.
2. Or, develop an ASP.NET MVC Partial View for product listing and use on both pages.
Partial View Advantages in ASP.NET MVC
So, using Partial View in ASP.NET MVC has following advantages:
- Enhances reusability by packaging up common website code instead of repeating the same in different pages.
- Easy to maintain. Changes in future are simple to accommodate.
Rendering a Partial View inside another View is quite simple by using Html.RenderPartial function and passing Partial view name as parameter to it.