Walk into ASP. NET MVC: [3] Create a controller

Source: Internet
Author: User

In fact, the controller is a class, a class that inherits from the controller. Create a controller normally, and the problem is that ASP. NET MVC provides a convenient way to create an action automatically when you create a controller.

1 Open the project, right-click on the Controller folder, select, create Controller

2 Enter the controller name, click OK; Note that controller names generally have controllers as suffixes

The 3 framework creates this controller, continues to self-controllers, and generates an action named index by default

4 The view is not actually generated automatically

5 if we want to automatically generate a set of action, such as additions and deletions, it is not more effort? In fact, supported. That is, when we created it, we chose an empty MVC controller, and we could choose a class that would allow the framework to automatically generate the corresponding action and view.

6 Create a new controller, choose to use the template, this template can meet our requirements above

7 First select a context, that is, the database represents the entity class, which we will enter a name when using EF to generate a database entity, typically the same name as the edmx file in model

8 then select a class (equivalent to a table in the database), so that we need to do a domain name additions and deletions function, then you can choose class domain; Click Add

9 If we want to specify a template for the view that will be generated, you can click Advanced options in the lower right corner, where you can specify a template layout

10 generate a good controller and its view; These functions are almost directly available except for some changes, which can save a lot of repetitive work

11 The function of the generator controller is introduced here for the time being, wish you to study happily!

I original, reproduced annotated source. Better visual typesetting please visit: Http://t.cn/RP6lxub

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.