国产探花免费观看_亚洲丰满少妇自慰呻吟_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"];


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 庆阳市| 稷山县| 榆中县| 洪泽县| 越西县| 余干县| 曲松县| 青神县| 方城县| 河南省| 八宿县| 灵武市| 北宁市| 遵化市| 奇台县| 安远县| 抚远县| 祁门县| 民权县| 牙克石市| 保德县| 江西省| 伊吾县| 全南县| 仁寿县| 合阳县| 喀什市| 民乐县| 博白县| 犍为县| 临邑县| 定远县| 正阳县| 泰来县| 阿荣旗| 高邑县| 泸西县| 沾益县| 红桥区| 永修县| 楚雄市|