在 bundleconfig 中添加引导程序在 asp.net mvc 中不起作用 [英] Adding bootstrap in bundleconfig doesn't work in asp.net mvc

查看:13
本文介绍了在 bundleconfig 中添加引导程序在 asp.net mvc 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我通过 nuget 包控制台安装了引导程序.

I installed bootstrap via nuget package console.

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

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.

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

推荐答案

使用 Bundle 时,不要附加 .min

When using Bundle, do not append the .min

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

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

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

  • debug="true" - 将使用非缩小版本.
  • debug="false" - *.min.css 将被搜索,如果没有找到,当前将被缩小
  • 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 设置:

web.config setting:

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

这篇关于在 bundleconfig 中添加引导程序在 asp.net mvc 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆