Understanding the Controller
The MVC controller handles requests for the ASP.net MVC Web site, and each browser request is mapped to a special controller, for example, if you enter the following URL in your browser's address bar:
Http://localhost/Product/Index/3
The Productcontroller controller is invoked and the productcontroller is responsible for generating the corresponding response from the browser request, for example, the controller may return a specific view to the browser, or the controller will redirect the user to another controller.
Create a new controller under your asp.net MVC application's Controller folder, right-click on the Controller folder, select Add > New Project, and then select the MVC Controller class template (shown in Figure 1), the controller name suffix must include controller, for example, Productcontroller Controller.
Figure 1 Creating a new controller
If you create a new controller named Productcontroller, your file content is shown in Listing 1.
Listing 1 Productcontroller.vb
Public Class productcontroller
Inherits System.Web.Mvc.Controller
Function Index ()
' Add action log ' IC here
Throw the New
notimplementedexception () End Function End Class
As you can see in Listing 1, the controller is a class (Visual Basic. NET or C # class, the controller is a class derived from the System.Web.Mvc.Controller base class, because the controller inherits the class and therefore inherits several useful methods.