NFinal controller-URL, nfinal controller url
URL routing rules
Rule: http: // URL/Module name/controller relative path file name/example name .htm
Example: http: // localhost/App/IndexController/Index.htm
Http: // localhsot/App/Admin/IndexController/Index.htm
Passing Parameters
Http: // URL/Module name/controller relative path file name/function name/parameter name 1/parameter value 1/.../parameter name N/response value n.htm
Example: http: // localhost/App/IndexController/Index/id/1.htm
Http: // localhost/App/ListController/Index/pageSize/5/pageIndex/1.htm
Obtain URL parameters
Add some parameters to the Controller method, such as user, and then output.
1 using System; 2 using System. collections. generic; 3 using System. web; 4 namespace WebMvc. app. controllers 5 {6 public class SampleController: Controller 7 {8 public void Show (string user) 9 {10 Write (string. format ("Hello {0 }. ", user); 11} 12} 13}Controller Code
Run WebCompiler. aspx to regenerate.
The Web/Default/SampleControler folder is included in the project.
The Show. cs code is as follows:
1 using System. collections. generic; 2 using System. web; 3 namespace WebMvc. app. web. default. sampleController 4 {5 public class ShowAction: Controller 6 {7 public ShowAction (System. IO. textWriter tw): base (tw) {} public ShowAction (string fileName): base (fileName) {} 8 public void Show (string user) 9 {10 Write (string. format ("Hello {0 }. ", user); 11} 12} 13}Show. cs Code
Modify the URL in show.html
URL: http: // localhost/App/SampleController/Show/user/Lucas.htm
In show.html, the Code is as follows:
1 The browser outputs Hello Lucas.
Parameter description
NFinal will automatically help you convert the parameter types you need, but you must ensure that the parameter names are consistent before and after,
Parameters in the function can obtain not only the parameters in the URL, but also the parameters in POST.
But NFinal does not support obtaining? Id = 1.
The parameter type can be int, string, float, or other basic types.
Of course, the built-in _ get variable of Controller can also be obtained and converted manually like the traditional ASPX variable.
For example, string user = _ get ["user"];