[英]Adding Bundles to existing ASP.NET Webforms solution
I am trying to add Bundles to an existing ASP.NET Webforms solution but my bundles always render empty and I am unsure why. 我试图将捆绑软件添加到现有的ASP.NET Webforms解决方案中,但是我的捆绑软件始终呈现空白,我不确定为什么。 I have been following this blog post .
我一直在关注此博客文章 。
So far I have: 到目前为止,我有:
Global.asax.cs Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
App_Start/BundleConfig.cs App_Start / BundleConfig.cs
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkID=303951
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/Global").Include(
"~/js/jquery-{version}.js",
"~/js/jquery-ui.js"));
bundles.Add(new ScriptBundle("~/bundles/GlobalHead").Include(
"~/js/modernizr*"));
bundles.Add(new StyleBundle("~/Content/Global").Include(
"~/css/site.css"));
}
}
Site.Master 网站主
<head runat="server">
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundle/GlobalHead") %>
<%: Styles.Render("~/Content/Global") %>
</asp:PlaceHolder>
</head>
<body>
<%: Scripts.Render("~/bundle/Global") %>
</body>
Web.Config Web配置
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
Update 更新资料
To be clear, when I open a web page and inspect the resources with chrome dev tools, I can see 明确地说,当我打开网页并使用chrome开发工具检查资源时,我可以看到
Content/Site.css
bundle/Global.js
bundle/GlobalHead.js
But when inspecting them they have no content. 但是在检查它们时,它们没有内容。
Simple solution, I had some typing errors. 简单的解决方案,我有一些输入错误。
In the Site.Master I missed the 's' from the end of bundles. 在Site.Master中,我错过了包尾的's'。 Making my Site.Master look like this.
使我的Site.Master看起来像这样。
<head runat="server">
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/GlobalHead") %>
<%: Styles.Render("~/Content/Global") %>
</asp:PlaceHolder>
</head>
<body>
<%: Scripts.Render("~/bundles/Global") %>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.