簡體   English   中英

將js包含在asp.net應用程序的Bundle.config中

[英]Include js in Bundle.config in asp.net application

我正在嘗試將我的ASP.NET Web應用程序的CSS和JS捆綁在一起。 CSS可以正常工作,但也可以將js文件作為CSS。 可能是我做錯了配置。 當我調試我的應用程序並查看頁面源代碼時,它會顯示如下內容。

<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/Site.css" rel="stylesheet"/>
<link href="/Content/owlcarousel.css" rel="stylesheet"/>
<link href="/Scripts/jquery.js" rel="stylesheet"/>
<link href="/Scripts/owlcarousel.js" rel="stylesheet"/>

Bundle.config

<?xml version="1.0" encoding="utf-8" ?>
<bundles version="1.0">
  <styleBundle path="~/Content/css">
    <include path="~/Content/bootstrap.css" />
    <include path="~/Content/Site.css" />
    <include path="~/Content/owlcarousel.css" />
  </styleBundle>

  <scriptBundle path="~/Scripts/js">
    <include path="~/Scripts/jquery.js" />
    <include path="~/Scripts/owlcarousel.js" />
  </scriptBundle>
</bundles>

母版

<asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>
    <webopt:bundlereference runat="server" path="~/Content/css" />
    <webopt:bundlereference runat="server" path="~/Scripts/js" />

雖然我不知道解決方案的確切原因,但我可能會提出一些猜測。

看來您需要使用<asp:PlaceHolder runat="server"><%: Scripts.Render("~/Scripts/js") %></asp:PlaceHolder>來獲取Bundle.config scriptBundle引用才能正確呈現。

我在搜索過程中看到了一篇文章(現在有點迷失了),注意到“ webopt:BundleReference”對Styles.Render進行了調用……這是我和您所經歷的,即Microsoft將Styles.Render應用於scriptBundle引用Scripts.Render!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM