Razor是asp.net MVC中默認的模板類型,當然這些語法也是很簡單的,其實Razor視圖引擎是輕量級和簡單的視圖引擎,下面錯新技術頻道小編就帶大家來了解Razor模板引擎簡單介紹吧!
核心代碼代碼封裝:
public static string ParseRazor(HttpContext context, string csHtmlVirtualPath, object model = null) { string fullpath = context.Server.MapPath(csHtmlVirtualPath);//將虛擬路徑轉換為絕對路徑 string cshtml = File.ReadAllText(fullpath); //將整個cshtml代碼讀取出來 string cacheName = fullpath + File.GetLastWriteTime(fullpath);//返回上次寫入指定文件或目錄的日期和時間。 string html = Razor.Parse(cshtml, model, cacheName); return html; } /// <summary> /// 直接將讀取的cshtml代碼轉換完后,直接返回給客戶端 /// </summary> /// <param name="context"></param> /// <param name="csHtmlVirtualPath"></param> /// <param name="model"></param> public static void OutputRazor(HttpContext context, string csHtmlVirtualPath, object model = null) { string html = ParseRazor(context, csHtmlVirtualPath, model); context.Response.Write(html); } 上文是錯新技術頻道小編為大家帶來的Razor模板引擎簡單介紹,因為它是在后臺有很多數據的情況下動態讀取數據庫信息,將繁瑣的拼接封裝在后臺。
新聞熱點
疑難解答
圖片精選