ASP.NET MVC - Controllers
To learn ASP.NET MVC, we will build an Internet application.
Part 4: Adding a Controller.
Controllers Folder
The Controllers folder contains controller classes responsible for handling user input and responses.
MVC requires all controller files to end with "Controller".
In our example, Visual Web Developer has already created the following files: HomeController.cs (for the Home and About pages) and AccountController.cs (for the login page):
Web servers typically map incoming URL requests directly to files on the server. For example, a URL request "http://www.w3cschool.cc/index.php" would map directly to the file "index.php" in the server's root directory.
The MVC framework maps URLs differently. MVC maps URLs to methods within classes known as "controllers".
Controllers are responsible for handling incoming requests, processing input, saving data, and sending responses back to the client.
Home Controller
In our application, the controller file HomeController.cs defines two actions, Index and About.
Replace the contents of the HomeController.cs file with:
Controller Views
The files Index.cshtml and About.cshtml in the Views folder define the views for the ActionResult methods Index() and About() in the controller.