我在项目的母版页中定义了 CSS 样式表。在从母版页继承的页面/ View 之一上,我需要添加另一个 CSS 样式表(我也可以内联添加它,尽管我不愿意)。
但是,我不知道如何做到这一点。这可能吗?
最佳答案
在您的母版页中,您可以拥有
<!-- in Master Page -->
<head runat="server">
<link href="Style.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="header" runat="server">
</asp:ContentPlaceHolder>
</head>
在您的 View 页面中,您可以在标题中添加更多内容,
<!-- in view Page -->
<asp:Content ID="viewContent" ContentPlaceHolderID="header" runat="server">
<link href="Style1.css" rel="stylesheet" type="text/css" />
</asp:Content>
最终页面将呈现为
<head runat="server">
<link href="Style.css" rel="stylesheet" type="text/css" />
<link href="Style1.css" rel="stylesheet" type="text/css" />
</head>
关于c# - 如何有条件地向 ASP.NET MVC 页面添加一些 CSS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2485511/