c# - 在 bundleconfig 中添加 Bootstrap 在 asp.net mvc 中不起作用

标签 c# asp.net-mvc twitter-bootstrap asp.net-mvc-4

我遇到了一个问题,在我看来很奇怪。

我通过 nuget 包控制台安装了 bootstrap。

之后,在 BundleConfig.cs 文件中,我将两项添加到 bundles 列表中:

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                    "~/Scripts/bootstrap.min.js"));

bundles.Add(new StyleBundle("~/Content/bootstrap").Include(
                     "~/Content/bootstrap.min.css", 
                     "~/Content/bootstrap-theme.min.css"));

当然,这些文件存在于本地。

_Layout.cshtml 文件包含

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    @Styles.Render("~/Content/bootstrap")

</head>
<body>
    @RenderBody()

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

但是当我看到一个 View (例如登录页面)时,我发现 bundle 没有附加 bootstrap 部分。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>
    <link href="/Content/Site.css" rel="stylesheet"/>
    <script src="/Scripts/modernizr-2.6.2.js"></script>    
    <!-- I expect bootstrap here but it is not displayed -->
</head>
<body>

...

<script src="/Scripts/jquery-1.9.1.js"></script>
<!-- I expect bootstrap here but it is not displayed -->
</body>
</html>

最佳答案

使用 Bundle 时,不要附加 .min

bundles.Add(new StyleBundle("~/Content/bootstrap").Include(
    "~/Content/bootstrap.css", 
    "~/Content/bootstrap-theme.css"));

基于调试设置,(主要是 web.config)

  • debug="true" - 将使用非缩小版本。
  • debug="false" - *.min.css 将被搜索,如果没有找到,当前将被缩小

web.config 设置:

<system.web>
  <compilation debug="true"...

关于c# - 在 bundleconfig 中添加 Bootstrap 在 asp.net mvc 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20869907/

相关文章:

c# - 如何通过uploadcare中的rest api删除文件

c# - 创建 View 中可用的自定义助手

javascript - 使用 Parsley 和模态窗口进行验证

html - 更改 css 下拉子菜单字体大小

c# - 将公共(public)方法重构到另一个类

c# - 如何防止 SQL Server 存储过程与 EF 并发执行?

c# - HttpRequest 什么时候被创建?

asp.net-mvc - Html.BeginForm 在 Controller 中调用正确的操作

twitter-bootstrap - bootstrap css - 如何在不影响背景的情况下制作模态对话框模态

c# - 独立于 DataTable 存储 DataRow - RowNotInTableException