Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

I installed bootstrap via nuget package console.

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

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

<!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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
384 views
Welcome To Ask or Share your Answers For Others

1 Answer

When using Bundle, do not append the .min

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

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

  • debug="true" - the non minified version will be used.
  • debug="false" - *.min.css will be searched, and if not found, the current will be minified

web.config setting:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...