To create the reusable components we will use the Partial Views. There are two types of Partial Views:
Static partial view: It will return static data
@html.RenderPartial(“Partial view”); Will return void displays ouput on viewpage.
@html.Partial(“partialview”): Return MVC HTML string , you can store it in particular variable.
Dynamic partial view: To implement dynamic data
@html.Action(“partialview”):Will return MVC html string
Let us see partial view example step by step:- Step 1:
Create new project called "AspnetMVCPartialViewDemo"
Now we are going to create 2 partial views , one is Navigationbar partial view and another one is FooterPartial view. Step 3:
Go to Shared folder and create NavBarPartialview.cshtml
Create another partial view called "FooterView.cshtml"
Eventually modify _Layout.cshtml to invoke both Navigationbar and Footer partial views.