我创建了一个新的MVC项目(简单模板),运行时一切正常。但当我更新NuGet包后,运行我的项目时出现了错误:
System.NullReferenceException:对象引用未设置为对象的实例
在调试模式下,这个错误是由这一行引起的:
@Scripts.Render("~/bundles/bootstrap")
我没有更改任何代码,只是更新了 NuGet 包。我的捆绑包看起来很标准,就像这样:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
我已安装Bootstrap并且所有文件都在正确的目录中(css在Content
,js在Scripts
)。
有趣的是,当我将ScriptBundle
更改为Bundle
时,它开始工作了。无论如何,我认为这不是一个合适的解决方案,你有什么办法让它使用标准的ScriptBundle
来运行吗?