簡體   English   中英

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

[英]Adding bootstrap in bundleconfig doesn't work in asp.net mvc

我遇到了一個問題,在我看來很奇怪。

我通過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>

但是當我看到一個視圖(例如登錄頁面)時,我看到該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"...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM