Types of views in MVC - ASP.Net
There are 3 types of view available in MVC
- View page
- Master page view
- Partial view
- View page:
In general, this is inherited from the view page class to create a normal page within MVC, we use this view
In general, to create this view we use the view page template, i.e., MVC to view page template in MVC application.
The inherited class name will be available in <%@ page directive with inherits attributes.
To create a view page that contains a master page we use a template known as “MVC2 view content page”.
- Master page view:
This is used to create a master page within the MVC application.
To create a master page view we use a template known as “MVC2 view master page.”
This is going to inherit a clan i.e., “system.web.MVC.view master page” it is possible to create the master page dynamically in MVC just like in ASP.net
The master page view will have a default extension of. master
Learn ASP.Net by Tekslate - Fastest growing sector in the industry. Explore Online "ASP.Net Training" and course is aligned with industry needs & developed by industry veterans. Tekslate will turn you into ASP.Net Expert.
- Partial views:
Partial views are similar to the user controller in ASP.net
This will have a default extension of. ascx similar to ASP.net user controller
This is inherited from the class “system.web.mvc.view user control”.
In general, this can be included in any other view page just like in ASP.net user controllers.
Creating a view page:
Go to solution explorer
Select the home folder from views
Click with RM button
Click on add
Click on a new item
Select MVC2 view page template
Type the view name (sample.asp x)
Click on add
Go to the source part of the page
Type following in body part
<H2> welcome to satya technologies</H2>
Go to controls folder
Double click on home controller .cs
Add new action method with the name (sample)
Like
Public action result sample ()
{
Return view ();
}
To run this page directly
Go to register routes method
Change the action name from index to sample
- Creating a master view page:
Go to solution explorer
Select a shared folder from views folder
Click with RM button
Click on add
Click on a new item
Select MVC2 view master page template
Type the master page name (abc.master)
Click on add
Go to source part --> write the following code
<Body>
<h1 align=’center’>satya technologies </h1>
</body>
Creating a content page:
Select the home folder from views
Click with RM button
Click on add
Click on a new item
Select MVC2 view content page template
Type the content page name (cp1.aspx)
Click on add
A select master page dialogue box is displayed
Select the abc.masteràclick on ok
To run this page use the following steps
Go to the home controller .cs file
Write the code for action result
Public action result cp1 ()
{
Return view ();
}
Then go to global.asax file
Change the action name to cp1.
Run the application and check
For in-depth understanding click on
- ASP. NET web applications and ASP. NET MVC Application.
- Object initialization
- Razor syntax
- Collection Initialize ASP.net
- View engine & Razor view engine