2015年8月12日 星期三

【ASP.NET MVC】ref CSS to specified view

指定 CSS 檔給特定的 view (而非 layout)

在 view 中加入
  1. @section styles {
  2. <link href="@Url.Content("~/Content/xxx.css")" rel="stylesheet" type="text/css" />
  3. }
之後在該 view 的 layout 補上
  1. @RenderSection("styles", false)
如果沒加上面那串你會碰到
下列區段已定義但尚未為版面配置頁 "~/Views/Shared/_XXX.cshtml" 呈現: "styles"。
的錯誤。

ref:stackoverflow1stackoverflow2

沒有留言:

張貼留言