【问题标题】:Access to head tag in content pages (ASP.NET MVC)访问内容页面中的 head 标记 (ASP.NET MVC)
【发布时间】:2018-02-16 21:27:30
【问题描述】:

我想访问我的内容页面 (ASP.NET MVC) 中的 <head> 标记部分。 例如,我想在几个内容页面的<head> 标记中放置一个CSS 文件链接。我该怎么做?

【问题讨论】:

  • 查看html head
  • 这就是部分的用途。
  • 你没明白我的意思。我想访问 CONTENT PAGES (ASP.NET MVC) 中的 head 标签

标签: html asp.net asp.net-mvc layout


【解决方案1】:

您想使用部分。

在你的共享布局中,通常是_Layout.cshtml,像这样添加一个RenderSection

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
     @RenderSection("css", required: false)
</head>

然后在要应用css的内容页面中,添加以下内容

@section css{
    <!-- whatever stylesheets you want to link to your content page-->
    <link rel="stylesheet" href="/SomeStyles.css">
}

现在,当您的内容页面被渲染时,您的页面特定 css 将被添加。

【讨论】:

    猜你喜欢
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多