ASP.NET MVC - Views

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

Part 5:Add views to display the application.

Views folder

Views The folder stores files related to the application display (user interface), such as HTML files. Depending on the language, the file extensions may be html, asp, aspx, cshtml, or vbhtml.

The Views folder contains a folder for each controller.

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

The Account folder contains pages for registering and logging in to user accounts.

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 (template pages and layout pages) shared between controllers.

ASP.NET File Types

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

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

Index File

The Index.cshtml file represents the home page of the application. It is the default file of the application (home page file).

Write the following content to the file:

@{ViewBag.Title = "Home Page";}
<h1>Welcome to CodeW3C.com</h1>
<p>Put Home Page content here</p>

About File

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

Write the following content to the file:

@{ViewBag.Title = "About Us";}
<h1>About Us</h1>
<p>Put About Us content here</p>

Run the Application

Select Debug and start debugging from the Debug menu (or press F5).

Your application will look something like this:

Please click 'Home' and 'About' to see how it runs.

Congratulations to you

Congratulations. You have created your first MVC application.

Note:The 'Movie' tab still cannot be clicked. We will add code for the 'Movie' tab in a later chapter of this tutorial.