Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP.NET MVC Views

ASP.NET MVC - Views


To learn ASP.NET MVC, we will build an Internet application.

Part 5: Add views for displaying the application.


The Views folder

Views The folder stores files (HTML files) related to the application's display (user interface). Depending on the language used, these files may have the extensions html, asp, aspx, cshtml, and vbhtml.

The Views folder contains one folder for each controller.

In the Views folder, Visual Web Developer has created an Account folder, a Home folder, and a Shared folder.

The Account folder contains pages for user account registration and login.

The Home folder is used to store application pages such as the home page and about page.

The Shared folder is used to store views shared between controllers (master pages and layout pages).

Views


ASP.NET file types

The following HTML file types can be seen in the Views folder:

File type Extension
Plain HTML .htm or .html
Classic ASP .asp
Classic ASP.NET .aspx
ASP.NET Razor C# .cshtml
ASP.NET Razor VB .vbhtml

Index file

The file Index.cshtml represents the application's Home page. It is the application's default file (home page file).

Write the following content into the file:

@{ViewBag.Title = "Home Page";}

Welcome to runoob.com

Put Home Page content here


About file

The file About.cshtml represents the application's About page.

Write the following content into the file:

@{ViewBag.Title = "About Us";}

About Us

Put About Us content here


Run the application

Select Debug, then start debugging Start Debugging from the Visual Web Developer menu (or press F5).

Your application will be displayed as follows:

MVC Application

Click the "Home" tab and the "About" tab to see how it works.


Congratulations

Congratulations. You have created your first MVC application.

**Note:** You cannot click the "Movies" tab yet. We will add code for the "Movies" tab in a later chapter of this tutorial.