【问题标题】:Include CSS file in view在视图中包含 CSS 文件
【发布时间】:2011-12-02 03:36:45
【问题描述】:

在我看来,我将母版页包含如下:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mall.Master" Inherits="System.Web.Mvc.ViewPage<DomainModel.Entities.Seller>" %>

在我的 Mall.master 文件中,我添加了一个包含通用 css 文件的链接

      <link rel="Stylesheet" href="../../Content/MallMaster.css"  type="text/css" />

但是,在我看来,我需要另一个更具体用途的 css 文件 CheckOut.css。由于 Checkout.css 中定义的样式仅适用于一页,因此我不想在母版页中包含该文件。有什么方法可以将文件包含在我的视图中?

【问题讨论】:

    标签: asp.net asp.net-mvc


    【解决方案1】:

    您应该在 MasterPage 中添加一个新的 content () 占位符,然后在您的视图中您可以向该占位符添加另一个 css。

    标题>

    这可能对你有帮助 - How to pass page’s meta tags in ASP.NET MVC?

    【讨论】:

      【解决方案2】:

      如果您不想覆盖母版中的现有标签,您也可以在head 标签中添加内容占位符

      <head runat="server">
          <title>
              <asp:ContentPlaceHolder ID="title" runat="server">
                  Default Title</asp:ContentPlaceHolder>
          </title>
          <!-- The ContentPlaceHolder is placed inside the title tag to make sure that the
               document validates in the VS editor - <title> needs to be a direct child of
               <head>. The output will validate. -->
      
          <script src="theAllFamous_jQuery.js" type="text/javascript" />
          <link href="sitewide.css" type="text/css" rel="Stylesheet" />
          <asp:ContentPlaceHolder ID="headContent" runat="server />
      </head>
      

      在你看来:

      <asp:Content ID="title" ContendPlaceHolderId="title" runat="server">
          Page specific title
      </asp:Content>
      
      <asp:Content ID="head" ContentPlaceHolderId="headContent" runat="server">
          <link href="pagespecific.css" type="text/css/ rel="Stylesheet" />
      </asp:Content>
      

      这样您就不必在网站上的所有头标签中复制您想要的代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-08-24
        • 2011-03-19
        • 2023-03-06
        • 2010-10-29
        • 1970-01-01
        • 1970-01-01
        • 2019-12-06
        相关资源
        最近更新 更多