NFinal is the secret controller.

Source: Internet
Author: User

NFinal is the secret controller.

Projects developed using the NFinal framework are similar to MVC development methods, including the Controller layer, Model layer, and View layer, as well as the presentation layer Web layer, the Code actually executed in the NFinal Development Project is the code in the Web layer. The code in the Web is the Execution Code generated according to the code in the Controller and View template, we only need to write the logic in the Controller, design the page in the View, and then run WebComplier. aspx can generate the entire Web folder, and then you only need to run the corresponding HTML page in the Web. First, let's look at the controller-related things.

Controller Definition

1. The controller must be written in the Controllers directory.

2. The namespace uses the default namespace. The class name must end with the Controller and inherit from the Controller base class.

3. the return value type of the function is void and the modifier is public.

Example:

1. Create SampleController. cs under Controllers

1 using System. collections. generic; 2 using System. web; 3 // because the project name and module name are different, the namespace will also be different, and the Code cannot be copied. 4 // You must manually add the class or change it to the correct namespace. 5 namespace WebMvc. app. controllers 6 {7 public class SampleController: Controller 8 {9 public void Show () 10 {11 Write ("Hello World. "); 12} 13} 14}Controller Code

2. Right-click WebCompiler. aspx and choose View in the browser.

Generation starts

Generation ends

Contains two files.

The Show. cs code is as follows:

1 using System; 2 using System. collections. generic; 3 using System. web; 4 5 namespace WebMvc. app. web. default. sampleController 6 {7 public class ShowAction: Controller 8 {9 public ShowAction (System. IO. textWriter tw): base (tw) {} 10 public ShowAction (string fileName): base (fileName) {} 11 public void Show () 12 {13 Write ("Hello World. "); 14} 15} 16}Show. cs Code

The code in Show.html is as follows:

1 <! DOCTYPE html> 2 The code in Show only redirects to and executes the Show () method under SampleController.

4. Right-click and select view in the browser. You can see that the browser outputs Hello World.

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.