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