MVC controller
returns many types of output to the view according to the data we need
for the application. In this article we will learn about PartialView
result type of MVC . So instead of going into the depth on the subject,
let us start with its practical implementation.
To know more about the Action result types please refer my previous article
What is ActionResult ?
It is the type of output format which is shown to the client .
It is the type of output format which is shown to the client .
What is PartialViewResult?
PartialViewResult is used to return the partial view , basically it is a class which implements the ViewResultBase abstract class that used to render partial view.
PartialViewResult class inherit from ViewResultBase class So it implements the properties and methods of ViewResultBase class which are used to work and render partial views. The following are the properties of PartialViewResult which are inherited from ViewResultBase.
Key points
PartialViewResult is used to return the partial view , basically it is a class which implements the ViewResultBase abstract class that used to render partial view.
PartialViewResult class inherit from ViewResultBase class So it implements the properties and methods of ViewResultBase class which are used to work and render partial views. The following are the properties of PartialViewResult which are inherited from ViewResultBase.
Key points
- It does not uses layout page since it render in to the main view which has already layout page.
- It used to return the portion of web page instead of whole page.
- It does not fire all page events like main view.
- Its called into the main view to show list of records and other data to the user.
- Model
- TempData
- View
- ViewBag
- ViewData
- ViewEngineCollection
- ViewName
- ExecuteResult
- FindView
- Equals()
- Finalize()
- GetHashCode()
- GetType()
- MemberwiseClone()
- ToString()
Step 1 : Create an MVC application
- "Start", then "All Programs" and select "Microsoft Visual Studio 2015".
- "File", then "New" and click "Project" then select "ASP.NET Web Application Template", then provide the Project a name as you wish and click on OK.
- Choose MVC empty application option and click on OK
Right click on Controller folder in the created MVC application ,give the class name Home or as you
and click on OK
HomeControlle.cs
public class HomeController : Controller { // GET: for main view public ActionResult Index() { return View(); } [HttpGet] public PartialViewResult EmpList() { //for partial view return PartialView(); } }
Step 2 : Add main view
Right click on Home folder inside the View folder in the created MVC application as
Give the name Index and click Add button.
Step 3 : Add partial view
Right click on Home folder inside the View folder in the created MVC application as
Step 4 : Run the application and call partial view by typing Home/EmpList with base address .it renders the page as
In the preceding example of partialview result ,you might be noticed that it has no layout page
Step 5 : Call Partial view in Main view
Write the following code into main view index to render the partial view
<div> @Html.Partial("EmpList") </div>
2 Comments
Thanks for providing good information,Thanks for your sharing.Angularjs Online Training
ReplyDeleteThanks for providing good information,Thanks for your sharing.Angularjs Online Course
ReplyDelete