规则:http://网址/模块名/控制器的相对路径的文件名/函数名.htmhtml
例: http://localhost/App/IndexController/Index.htm
http://localhsot/App/Admin/IndexController/Index.htm 浏览器
传参ide
http://网址/模块名/控制器的相对路径的文件名/函数名/参数名1/参数值1/.../参数名N/参数值N.htm 函数
例: http://localhost/App/IndexController/Index/id/1.htm
http://localhost/App/ListController/Index/pageSize/5/pageIndex/1.htm ui
在控制器的方法中加入一些参数,例如user,而后输出. spa
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 }
运行WebCompiler.aspx从新生成.
而后把Web/Default/SampleControler文件夹包括在项目中.
其中Show.cs代码以下 :3d
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.html文件中的URLcode
URL为:http://localhost/App/SampleController/Show/user/Lucas.htmorm
其中Show.html中的代码以下: xml
1 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title<</title< </head> <body> <script> window.location.href = "/App/SampleController/Show/user/Lucas.htm"; </script> </body> </html>
用浏览器查看Show.html.则浏览器输出Hello Lucas.
NFinal会自动帮你转换好你所须要的参数类型,但必须保证参数名先后保持一致,
函数内的参数不只能够获取URL中的参数,一样也能够获取POST中的参数.
但NFinal不支持获取?id=1这样的参数.
参数类型能够为int,string,float等基本类型.
固然Controller内置的_get变量也能够像传统的ASPX那像手动获取并转换参数.好比string user=_get["user"];