Nfinal's Secret Controller

Source: Internet
Author: User

projects developed with the Nfinal framework are similar to the way MVC is developed, with the controller layer, the model layer, the view layer, and the presentation Layer Web layer, the code that is actually executed in the project developed by Nfinal, which is the code in the Web layer. The code in the Web is the execution code generated from the code in the Controller and the view template, we just need to write logic in the controller, design the page in view and run webcomplier.aspx to create the entire Web folder, and then just run the appropriate HTML page in the Web. So first look at the controller-related stuff.



Definition of the Controller

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

2. The namespace takes the default namespace, and the class name must end with a controller and must inherit from the Controller base class.

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


Cases:

1, the new SampleController.cs under the controllers

 using System.Collections.Generic;        using  system.web;        //because the project name and module name are different, the namespace is different, and copying the code is not possible .         //must either manually add the class or modify it to the correct namespace .         namespace webmvc.app.controllers        {             public class SampleController:Controller             {                 public void show ()                  {                     write ("Hello World.");                 }             }        }

2. Right click webcompiler.aspx Select View in Browser

Build Start

Build End

3. Refreshing the project folder will reveal that the Samplecontroller folder appears under the default folder on the Web tier. Right click on the folder selection included in the project, you can see the folder has Show.cs and show.html two files.

The code for Show.cs is as follows:

 using System;        using System.Collections.Generic;         using System.Web;         namespace WebMvc.App.Web.Default.SampleController         {            public class  showaction  : controller        {         public showaction (SYSTEM.IO.TEXTWRITER TW): Base (TW) {}         public showaction (String filename)  : base (fileName)  {}                public  void show ()                  {    &nbSp;               write ("Hello  world. ");                 }             }        }

show.html is as follows:

 <! Doctype html>        

The code in show just jumps and executes the show () method under Samplecontroller.


4. Right-click and select View in browser. You can see the browser output Hello world.



Nfinal's Secret Controller

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.