twitter-bootstrap 将 CSS 添加到视图或部分视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18762527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 18:22:17  来源:igfitidea点击:

Add CSS to a View or Partial View

asp.net-mvcasp.net-mvc-4twitter-bootstrap

提问by ali

I am working on a MVC application which have its own CSS and it works perfectly. My problem is that I want to use bootstrap popup at one of my view. When I add Bootstap CSS to layout View it conflicts and disturbs my orignal CSS. Now can some one please tell me how to include Bootstrap CSS at just that view where I require it. Any Example will be helpful thanks

我正在开发一个 MVC 应用程序,它有自己的 CSS 并且运行良好。我的问题是我想在我的一个视图中使用引导弹出窗口。当我将 Bootstap CSS 添加到布局视图时,它会冲突并干扰我的原始 CSS。现在有人可以告诉我如何在我需要的那个视图中包含 Bootstrap CSS。任何例子都会有帮助谢谢

回答by AthibaN

If you don't want the original CSS in that particular View, this would help, The CSS file is referenced in the _Layout.cshtmlfile. So in order to reference your new CSS file instead of the original CSS, you have to explicitly set Layout of that View to nullat the start of the page (as the page has the link to _Layout.cshtmlby default) and add a link to your CSS, like

如果您不希望在该特定视图中使用原始 CSS,这会有所帮助,文件中引用了 CSS_Layout.cshtml文件。因此,为了引用您的新 CSS 文件而不是原始 CSS,您必须null在页面开头显式设置该视图的布局(因为该页面_Layout.cshtml默认具有链接)并添加指向您的 CSS 的链接,喜欢

@{
    Layout = null;
}
<link href="@Url.Content("~/MYNEWCSS.css")" rel="stylesheet" type="text/css" />

But the downside is, as you can expect, the _Layout.cshtml page's content won't be available in that particular page. Let me know if it helps. Cheers.

但缺点是,正如您所料,_Layout.cshtml 页面的内容在该特定页面中将不可用。如果有帮助,请告诉我。干杯。

回答by Amit

Use below line after bootstrap.css

在 bootstrap.css 之后使用下面的行

<link href="@Url.Content("~/MYNEWCSS.css")" rel="stylesheet" type="text/css" />