在bundleconfig添加自举不asp.net mvc的工作 [英] Adding bootstrap in bundleconfig doesn't work in asp.net mvc

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

问题描述

我在的观点遇到了一个问题,怪怪的。

我通过的NuGet包控制台安装引导。

之后,在 BundleConfig.cs 文件,我添加了两个项目清单:

  bundles.Add(新ScriptBundle(〜/包/引导)。包括(
                    〜/脚本/ bootstrap.min.js));bundles.Add(新StyleBundle(〜/内容/引导)。包括(
                     〜/内容/ bootstrap.min.css
                     〜/内容/引导-theme.min.css));

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

_Layout.cshtml 文件包含

<!DOCTYPE HTML>
< HTML和GT;
< HEAD>
    <间的charset =UTF-8/>
    < META NAME =视口CONTENT =WIDTH =设备宽度/>
    <标题> @ ViewBag.Title< /标题>
    @ Styles.Render(〜/内容/ CSS)
    @ Scripts.Render(〜/包/ Modernizr的)
    @ Styles.Render(〜/内容/引导)< /头>
<身体GT;
    @RenderBody()    @ Scripts.Render(〜/包/ jQuery的)
    @ Scripts.Render(〜/包/引导)
    @RenderSection(脚本,必需:false)
< /身体GT;
< / HTML>

但是,当我看到一个视图(例如登录页面),我看到包不追加引导一部分。

<!DOCTYPE HTML>
< HTML和GT;
< HEAD>
    <间的charset =UTF-8/>
    < META NAME =视口CONTENT =WIDTH =设备宽度/>
    <标题>登录和LT; /标题>
    <链接HREF =/内容/的site.css的rel =stylesheet属性/>
    <脚本的src =/脚本/ Modernizr的-2.6.2.js>< / SCRIPT>
    <! - 我希望在这里引导但不显示 - >
< /头>
<身体GT;...<脚本的src =/脚本/ jQuery的-1.9.1.js>< / SCRIPT>
<! - 我希望在这里引导但不显示 - >
< /身体GT;
< / HTML>


解决方案

在使用捆绑,没有附加 .min

  bundles.Add(新StyleBundle(〜/内容/引导)。包括(
    〜/内容/ bootstrap.css
    〜/内容/引导-theme.css));

根据调试设置(主要的web.config)


  • 调试=真正的 - 非缩小的版本将被使用。

  • 调试=false的 - * min.css 将被搜索,如果没有找到,。电流将精缩

web.config中设置:

 <&的System.Web GT;
  <编译调试=真?

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>

解决方案

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"...

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

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