asp.net MVC Tutorial: Understanding Controller, Controller behavior, and behavior results

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.