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

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

ASP.NET MVC學習筆記-Routing及視圖引摯解析原理

2019-11-17 04:02:20
字體:
來源:轉載
供稿:網友
首先打開項目的Global.asax.cs文件,我們將看到頁面重寫規則如下:

view plaincopy to clipboardPRint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
public static void RegisterRoutes(RouteCollection routes)   
{   
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");   
    routes.MapRoute(   
        "Default",                                              // Route name   
        "{controller}/{action}/{id}",                           // URL with parameters   
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults   
    );   
}   
protected void application_Start()   
{   
    RegisterRoutes(RouteTable.Routes);   
}  
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
        }
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }

MapRoute()重載如下:

view plaincopy to clipboardprint?
MapRoute( string name, string url);   
MapRoute( string name, string url, object defaults);   
MapRoute( string name, string url, string[] namespaces);   
MapRoute( string name, string url, object defaults, object constraints);   
MapRoute( string name, string url, object defaults, string[] namespaces);   
MapRoute( string name, string url, object defaults, object constraints, string[] namespaces);  
MapRoute( string name, string url);
MapRoute( string name, string url, object defaults);
MapRoute( string name, string url, string[] namespaces);
MapRoute( string name, string url, object defaults, object constraints);
MapRoute( string name, string url, object defaults, string[] namespaces);
MapRoute( string name, string url, object defaults, object constraints, string[] namespaces);

創建一個Route類實例,最關鍵的是為以下幾個屬性賦值:

屬性名稱 說明 舉例
Constraints  獲取或設置為 URL 參數指定有效值的表達式的詞典。  {controller}/{action}/{id}
DataTokens  獲取或設置傳遞到路由處理程序但未用于確定該路由是否匹配 URL 模式的自定義值。  new RouteValueDictionary { { "format", "short" } }
Defaults       獲取或設置要在 URL 不包含所有參數時使用的值。 new { controller = "Home", action = "Index", id = "" }
RouteHandler  獲取或設置處理路由請求的對象。 new MvcRouteHandler()
Url               獲取或設置路由的 URL 模式。  new { controller = @"[^/.]*" }

      asp.net MVC會將url請求根據重寫規則導向相應的controller中,然后在controller中調用相應的view()方法, 然后在ViewEngines中找到相匹配的ViewEngine查找并創建View實現頁面解析,ASP.net MVC提供了VirtualPathProviderViewEngine實現了查找View的功能。

     在IViewEngine中提供了母版及視圖的路徑格式字串的屬性,格式如下:

     MasterLocationFormats = new[] {
                "~/Views/{1}/{0}.master",
                "~/Views/Shared/{0}.master"
            };

       ViewLocationFormats = new[] {
                "~/Views/{1}/{0}.aspx",
                "~/Views/{1}/{0}.ascx",
                "~/Views//Shared/{0}.aspx",
                "~/Views/Shared/{0}.ascx"
            };

      PartialViewLocationFormats = ViewLocationFormats;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 惠来县| 永仁县| 营口市| 卢龙县| 芦山县| 乐安县| 普宁市| 白城市| 安岳县| 广灵县| 聂荣县| 九台市| 三亚市| 依安县| 团风县| 洛川县| 涞水县| 电白县| 红安县| 建阳市| 紫阳县| 普洱| 宜川县| 丹东市| 伊宁县| 溧阳市| 达州市| 邯郸市| 镶黄旗| 延安市| 宾阳县| 达尔| 筠连县| 中江县| 西丰县| 泸溪县| 正宁县| 静海县| 泾阳县| 大宁县| 广平县|