【问题标题】:Adding Bundles to existing ASP.NET Webforms solution将捆绑包添加到现有的 ASP.NET Webforms 解决方案
【发布时间】:2015-08-11 02:15:13
【问题描述】:

我正在尝试将捆绑包添加到现有的 ASP.NET Webforms 解决方案,但我的捆绑包总是呈现为空,我不确定为什么。我一直在关注this blog post

到目前为止我有:

  • 添加了 Microsoft ASP.NET Web 优化框架 NuGet 包
  • 确保包含所需的参考资料
  • 尝试在 Web.config 中使用 debug="false" 和 debug="true"
  • 在我的解决方案中添加了以下代码

Global.asax.cs

protected void Application_Start(object sender, EventArgs e)
{
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

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

<namespaces>
    <add namespace="System.Web.Optimization" />
</namespaces>

更新

需要明确的是,当我打开网页并使用 chrome 开发工具检查资源时,我可以看到

Content/Site.css
bundle/Global.js
bundle/GlobalHead.js

但是在检查它们时,它们没有内容。

【问题讨论】:

    标签: c# asp.net webforms bundle


    【解决方案1】:

    简单的解决方案,我有一些打字错误。

    在 Site.Master 中,我错过了捆绑包末尾的“s”。让我的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 2013-11-26
      • 2023-03-07
      • 1970-01-01
      相关资源
      最近更新 更多