This section introduces
ASP.NET MVC view, the View folder contains a folder corresponding to each controller, and each operation method has a corresponding view file with the same name. This provides the basis for the association of views and action methods.To learn ASP.NET MVC, we will build an Internet application.
Part 5: Add a view to display the application.
The Views folder stores files (HTML files) related to the application display (user interface). Depending on the language content, these files may have extensions such as html, asp, aspx, cshtml, and vbhtml.
The Views folder contains a 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 home page and about page.
The Shared folder is used to store views (master pages and layout pages) shared between controllers.
The following HTML file types can be seen 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 |
The file Index.cshtml represents the application's Home page. It is the application's default file (homepage file).
Write the following content in the file:
@{ViewBag.Title = "Home Page";} <h1>Welcome to w3cschool.cn</h1> <p>Put Home Page content here</p>
The file About.cshtml represents the application's About page.
Write the following content in the file:
@{ViewBag.Title = "About Us";} <h1>About Us</h1> <p>Put About Us content here</p>
Select Debug and start debugging from the Visual Web Developer menu Start Debugging (or press F5).
Your application will appear as follows:
Click on the "Home" tab and the "About" tab to see how it works.
Congratulations. You've created your first MVC application.
Note: You cannot click on the "Movies" tab yet. We'll add code for the "Movies" tab later in this tutorial.