简体   繁体   English

将js包含在asp.net应用程序的Bundle.config中

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

I am trying to bundle my css & js of my asp.net web application. 我正在尝试将我的ASP.NET Web应用程序的CSS和JS捆绑在一起。 CSS works fine but it also take js files as css. CSS可以正常工作,但也可以将js文件作为CSS。 May Be I have done some misconfiguration. 可能是我做错了配置。 When I dubug my application & looking at page source it gives shows like this. 当我调试我的应用程序并查看页面源代码时,它会显示如下内容。

<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 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>

MasterPage 母版

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

While I don't know the exact why's of the solution, I can hazard a few guesses. 虽然我不知道解决方案的确切原因,但我可能会提出一些猜测。

It appears you need to use <asp:PlaceHolder runat="server"><%: Scripts.Render("~/Scripts/js") %></asp:PlaceHolder> to get the Bundle.config scriptBundle reference to render correctly. 看来您需要使用<asp:PlaceHolder runat="server"><%: Scripts.Render("~/Scripts/js") %></asp:PlaceHolder>来获取Bundle.config scriptBundle引用才能正确呈现。

I saw an article during my search (sadly lost now) noting that "webopt:BundleReference" makes a call to Styles.Render...which is what I suspect you and I experienced, namely that Microsoft apply Styles.Render to scriptBundle references instead of Scripts.Render! 我在搜索过程中看到了一篇文章(现在有点迷失了),注意到“ webopt:BundleReference”对Styles.Render进行了调用……这是我和您所经历的,即Microsoft将Styles.Render应用于scriptBundle引用Scripts.Render!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM