Working with Partial View in MVC Razor
Hi everyone in this blog, I’m explaining about partial view
In general a Partial View is like a web user control in
ASP.Net applications. Partial Views and User Controls serve the same purpose.
ASP.NET MVC consists of three main parts - Model, View and
Controller. Model represents the business entity or domain object and it
manages the state of View. Controller controls the application logic and
communication between Model and View. A view represents the user interface,
which receives input from user and sends to controller for further action. In
this blog, I explain about ASP.NET MVC special views like Partial Views and
- A partial view can be used as a reusable component that
can be called or used from multiple and different views.
- A partial view contains reusable mark-up if you want to
render from inside multiple views.
- The partial view are used to render a consistent look
like header, footer, comments and so on.
Rendering Partial View: We can render a partial view
using one of the following 4:
Now in my example I will add a partial view. For this go to
Solution Explorer then select Views -> Shared Folder -> Right-click ->
Give a name to your View and check Create As a partial View as in
Now I am writing a line of text in this Partial View:
Now for the Home controller, here I add a new action
ShowMyPartialView(). So after it my Home Controller will look such as below:
Now for the View -> Home -> Index.cshtml.
Here I am rendering a Partial View using 4 types, so the index.cshtml will be
like the following:
ViewBag.Title = "Index";
Using Html.RenderPartial #</h5>
Using Html.Partial #</h5>
Using Html.RenderAction #</h5>
Using Html.Action #</h5>
in my next post i'll explain about Online and Offline Events