Partial View in ASP.NET Core MVC
A partial view is a view which is loaded into another view. Partial views are an efficient method of breaking large view into smaller modules. They can be used for reducing duplication of view content and on the same time making the view reusable.
Steps of creating Partial View in MVC
- Create a new project
- Goto web application, Select MVC.and provide the project name.
- Now,goto solution explorer and open Views
- Right click on Views and select Add and goto view option.
5. Give View name and tick the partial view option.
The difference between views and partial views, and the difference is more about their usage, rather than technical.
View is used as full page of our application, it needs a layout, <html>
and <title>
. Partial views are like reusable view which can be used in other views. Partials doesnot represent whole page, they are inserted in other views.
For implementing the partial view,while return View("SampleView");
renders a view page, So returning that same view by writing return PartialView("SampleView");
renders contents, but doesn't render the contents of layout page.
Partial View Features:
1. Light weighted and fits into any view
2. It can be used as a reusable component.
3. Partial view's are rendered inside another View.