tailieunhanh - Bài giảng Lập trình web: Controller - Nguyễn Hà Giang
Nội dung chính trong chương 2 gồm: Define and describe controllers, describe how to work with action methods, explain how to invoke action methods, explain routing requests, describe URL patterns. Mời các bạn tham khảo. | Controller Nguyen Ha Giang 1 Objectives Define and describe controllers Describe how to work with action methods Explain how to invoke action methods Explain routing requests Describe URL patterns 2 Working with Controllers A controller, in an app does the following Manages the flow of the app. Is responsible for intercepting incoming requests and executing the appropriate app code. Communicate with the models of the app and selects the required view to be rendered for the request. Is a C# class that extends the Controller class of the namespace. Allows separating the business logic of the app from the presentation logic. 3 Working with Controllers A controller is responsible to: Locate the appropriate method to call for an incoming request. Validate the data of the incoming request before invoking the requested method. Retrieve the request data and passing it to requested method as arguments. Handle any exceptions that the requested method throws. Help in rendering the view based on the result of the requested method. 4 Creating a Controller In MVC, the ControllerBase class of the namespace is the base class for all controllers. The Controllers class extends the ControllerBase class to provide a default implementation of a controller. To create a controller in an MVC app, you will need to create a C# class that extends the Controller class. Instead of creating a controller manually, you can use VS 2013 IDE, which also creates the folder structure for the application automatically. 5 Creating a Controller In VS 2013 IDE, you can create a controller by performing the following steps: Right-click the Controllers folder in the Solution Explorer window. Select Add Controller from the context menu that appears. The Add Scaffold dialog box is displayed. 6 Creating a Controller Select the Empty MVC Controller in scaffolding options. Type TestController in the controller name Click Add. The solution Explorer window . | Controller Nguyen Ha Giang 1 Objectives Define and describe controllers Describe how to work with action methods Explain how to invoke action methods Explain routing requests Describe URL patterns 2 Working with Controllers A controller, in an app does the following Manages the flow of the app. Is responsible for intercepting incoming requests and executing the appropriate app code. Communicate with the models of the app and selects the required view to be rendered for the request. Is a C# class that extends the Controller class of the namespace. Allows separating the business logic of the app from the presentation logic. 3 Working with Controllers A controller is responsible to: Locate the appropriate method to call for an incoming request. Validate the data of the incoming request before invoking the requested method. Retrieve the request data and passing it to requested method as arguments. Handle any exceptions that the requested method throws. Help in .
đang nạp các trang xem trước