在bundleconfig中添加bootstrap在asp.net mvc中不工作

时间:2021-09-19 03:19:44

I met an issue, strange in my point of view.

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

I installed bootstrap via nuget package console.

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

After that, in BundleConfig.cs file, I added two items to bundles list:

在那之后,在BundleConfig。cs文件,我添加了两项到bundle列表:

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"));

Of course, these files exist locally.

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

The _Layout.cshtml file contains

_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>

But when I see a view (for example login page), I see that bundle doesn't append bootstrap part.

但是当我看到一个视图(例如登录页面)时,我看到这个包没有附加引导部分。

<!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>

1 个解决方案

#1


61  

When using Bundle, do not append the .min

当使用Bundle时,不要附加.min

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

Based on the debug setting, (mostly web.config)

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

  • debug="true" - the non minified version will be used.
  • debug="true" -将使用非小型化版本。
  • debug="false" - *.min.css will be searched, and if not found, the current will be minified
  • debug = " false " - * .min。css将被搜索,如果没有找到,电流将被缩小

web.config setting:

网络。配置设置:

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

#1


61  

When using Bundle, do not append the .min

当使用Bundle时,不要附加.min

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

Based on the debug setting, (mostly web.config)

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

  • debug="true" - the non minified version will be used.
  • debug="true" -将使用非小型化版本。
  • debug="false" - *.min.css will be searched, and if not found, the current will be minified
  • debug = " false " - * .min。css将被搜索,如果没有找到,电流将被缩小

web.config setting:

网络。配置设置:

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