国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

NFinal 控制器—URL

2019-11-17 02:11:26
字體:
來源:轉載
供稿:網友

NFinal 控制器—URL

URL路由規則

規則: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

獲取URL參數

在控制器的方法中加入一些參數,例如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"];


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霍林郭勒市| 建昌县| 金寨县| 吉木萨尔县| 余庆县| 昆明市| 酉阳| 正镶白旗| 玉门市| 兴山县| 澄江县| 高邑县| 陵川县| 延川县| 东莞市| 新乡市| 岱山县| 阳原县| 甘泉县| 德化县| 秀山| 邵武市| 乌鲁木齐县| 清徐县| 西充县| 手机| 高密市| 芦山县| 儋州市| 界首市| 新安县| 淄博市| 临沧市| 株洲市| 平舆县| 本溪市| 景宁| 松阳县| 睢宁县| 连江县| 灌南县|