Asp.Net Core Mvc Razor之RazorPage

在AspNetCore.Mvc.Razor命名空間中的RazorPage繼承RazorPageBase,並定義的屬性爲:佈局

  • HttpContext Context 表示當前請求執行的HttpContext

RazorPageBase定義爲抽象類,並繼承了接口:IRazorPagecode

IRazorPage接口定義屬性以下:繼承

  • ViewContent ViewContent 獲取或設置渲染視圖的視圖上下文
  • IHtmlContent BodyContent 獲取或設置正文內容
  • bool IsLayoutBeingRendered 獲取或設置一個標誌,該標誌肯定是否呈現此頁面的佈局
  • string Path 獲取應用程序頁面的相對路徑
  • string Layout 獲取或設置佈局頁面的路徑
  • IDictionary<string, RenderAsyncDelegate> PreviousSectionWriters 獲取或設置此頁面能夠呈現的部分
  • IDictionary<string, RenderAsyncDelegate> SectionWriters 獲取此頁面定義的部分

定義的方法 以下:接口

  • Task ExecuteAsync(); 渲染頁面並將輸出寫入Writer
  • void EnsureRenderedBodyOrSections(); 驗證是否渲染了PreviousSectionWriters中定義的全部節,或者若是未定義節則渲染了正文

RazorPageBase中除了繼承IRazorPage中的屬性,還有定義的屬性以下:ip

  • DiagnosticSource DiagnosticSource 獲取或設置用於檢測頁面執行狀況的DiagnosticSource實例
  • HtmlEncoder HtmlEncoder 獲取此RazorPage處理非IHtmlContent C#表達式時要使用的HtmlEncoder
  • virtual TextWriter Output 獲取頁面正在將輸出寫入的TextWriter
  • ITempDataDictionary TempData 從ViewContext獲取ITempDataDictionary
  • virtual ClaimsPrincipal User 獲取當前登陸用戶的ClaimsPrincipal
  • object ViewBag 獲取動態視圖數據字典

能夠在Razor頁面中能夠直接使用的上述定義的屬性,其中RazorPage中的屬性Context爲ViewContent中的HttpContext
所以在Razor頁面中要獲取一些信息時,能夠直接使用上述屬性進行處理。ci

相關文章
相關標籤/搜索