規則:http://網址/模塊名/控制器的相對路徑的文件名/函數名.htm
例: http://localhost/App/IndexController/Index.htmhttp://localhsot/App/Admin/IndexController/Index.htm
傳參
http://網址/模塊名/控制器的相對路徑的文件名/函數名/參數名1/參數值1/.../參數名N/參數值N.htm
例: http://localhost/App/IndexController/Index/id/1.htmhttp://localhost/App/ListController/Index/pageSize/5/pageIndex/1.htm
在控制器的方法中加入一些參數,例如user,然后輸出.
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
運行WebCompiler.aspx重新生成.然后把Web/Default/SampleControler文件夾包括在項目中.其中Show.cs代碼如下 :
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
修改Show.html文件中的URL
URL為:http://localhost/App/SampleController/Show/user/Lucas.htm
其中Show.html中的代碼如下:
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 Code
用瀏覽器查看Show.html.則瀏覽器輸出Hello Lucas.
NFinal會自動幫你轉換好你所需要的參數類型,但必須保證參數名前后保持一致,函數內的參數不僅可以獲取URL中的參數,同樣也可以獲取POST中的參數.但NFinal不支持獲取?id=1這樣的參數.參數類型可以為int,string,float等基本類型.
當然Controller內置的_get變量也可以像傳統的ASPX那像手動獲取并轉換參數.比如string user=_get["user"];
新聞熱點
疑難解答