gpt4 book ai didi

c# - 将 Bundle 添加到现有的 ASP.NET Webforms 解决方案

转载 作者:IT王子 更新时间:2023-10-29 04:03:51 28 4
gpt4 key购买 nike

我正在尝试将 bundle 添加到现有的 ASP.NET Webforms 解决方案,但我的 bundle 始终呈现为空,我不确定为什么。我一直在关注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

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

最佳答案

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

在 Site.Master 中,我错过了 bundle 末尾的“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>

关于c# - 将 Bundle 添加到现有的 ASP.NET Webforms 解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30508805/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com