C# 为什么我的捆绑包即使包含在BundleConfig中也没有加载?
我有jQuery,我想在我的视图中加载引导包,我已经将它们添加到我的C# 为什么我的捆绑包即使包含在BundleConfig中也没有加载?,c#,asp.net-mvc,twitter-bootstrap,bundle,bundling-and-minification,C#,Asp.net Mvc,Twitter Bootstrap,Bundle,Bundling And Minification,我有jQuery,我想在我的视图中加载引导包,我已经将它们添加到我的bundleConfig中,并将其添加到@script.render中的视图中,但是我的脚本文件显然没有呈现,因为我甚至不能使用引导标记 捆绑包 using System.Web; using System.Web.Optimization; namespace XXXX { public class BundleConfig { // For more information on Bundl
bundleConfig
中,并将其添加到@script.render
中的视图中,但是我的脚本文件显然没有呈现,因为我甚至不能使用引导标记
捆绑包
using System.Web;
using System.Web.Optimization;
namespace XXXX
{
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/bootstrap.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/site.css",
"~/Content/bootstrap.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
}
\u 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")
</head>
<body>
<div>
<p>This is a test</p>
</div>
@RenderBody()
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>
@视图包。标题
@style.Render(“~/Content/css”)
@Scripts.Render(“~/bundles/modernizer”)
这是一个测试
@RenderBody()
@Scripts.Render(“~/bundles/jquery”)
@RenderSection(“脚本”,必需:false)
查看
@{
ViewBag.Title = "Search";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="jumbotron">
<div class="container">
<h1>Find</h1>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-primary" type="button">Go!</button>
</span>
</div>
</div>
</div>
</div>
</div>
@{
ViewBag.Title=“搜索”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
发现
走!
呈现的HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Search</title>
</head>
<body>
<div>
<div class="jumbotron">
<div class="container">
<h1>Find</h1>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-primary" type="button">Go!</button>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
搜寻
发现
走!
需要注意的是,捆绑和缩小是不同的过程。ASP.Net网站将其解释为:
捆绑
捆绑是ASP.NET 4.5中的一项新功能,它可以轻松地将多个文件合并或捆绑到单个文件中。您可以创建CSS、JavaScript和其他捆绑包。更少的文件意味着更少的HTTP请求,这可以提高第一页加载性能。
缩小
缩小对脚本或css执行各种不同的代码优化,例如删除不必要的空白和注释,并将变量名缩短为一个字符。考虑下面的JavaScript函数。
回到您的问题:ASP.Net MVC 4捆绑包具有忽略列表。还有.min
扩展名包含在忽略列表中。要覆盖忽略列表,请执行以下操作:
bundles.IgnoreList.Clear();
请发布呈现的响应。@Dai我已经更新了它。。。谢谢,请看一看。您是否查看了开发工具以尝试查看浏览器在哪里寻找您的捆绑包?这在调试和发布模式下都会发生吗?这在很大程度上取决于绑定机制,因为绑定机制基于设置的调试编译器指令创建优化。请尝试添加以下内容:
bundles.IgnoreList.Clear()
作为BundleConfig.cs
文件中的第一行