<webopt:bundlereference>将ScriptBundle呈现为css链接元素</webopt:bundlereference>

时间:2014-04-04 13:05:43

标签: javascript asp.net webforms web-optimization

我正在尝试使用新的.net 4.5 webforms控件来渲染我的materpage中的包。我在BundleConfig.cs中定义了一个scriptbundle,如下所示:

bundles.Add(new ScriptBundle("~/bundles/app").Include(
    "~/Scripts/underscore.js",
    "~/Scripts/backbone.js",
    "~/Scripts/app/app.js",
    "~/Scripts/app.validator.js",
    "~/Scripts/app/views/home.js",
    "~/Scripts/app/views/about.js",
    "~/Scripts/app/views/contact.js",
    "~/Scripts/app/controls/hello.js",
    "~/Scripts/app/init.js"));

然后我尝试使用新的<webopt:BundleReference>控件来渲染包:

<webopt:BundleReference ID="AppBundle" runat="server" Path="~/bundles/app"  />

但是当页面呈现时,输出为<link>个标签,而不是标签:

<link href="/Scripts/underscore.js" rel="stylesheet"/>
<link href="/Scripts/backbone.js" rel="stylesheet"/>
<link href="/Scripts/app/app.js" rel="stylesheet"/>
<link href="/Scripts/app/views/home.js" rel="stylesheet"/>
<link href="/Scripts/app/views/about.js" rel="stylesheet"/>
<link href="/Scripts/app/views/contact.js" rel="stylesheet"/>
<link href="/Scripts/app/controls/hello.js" rel="stylesheet"/>
<link href="/Scripts/app/init.js" rel="stylesheet"/>

此控件是否仅用于渲染样式?或者我做错了什么?如何使用webopt控件而不是<%: Scripts.Render() %>语法来渲染脚本包?

1 个答案:

答案 0 :(得分:0)

我正在使用VS2012和.Net 4.5。我使用webopt控件。我这样渲染:

<head>
  <asp:PlaceHolder runat="server">
    <%: Styles.Render("~/Content/MainContentCSS") %>
    <%: Scripts.Render("~/bundles/jqueryPlus") %>
  </asp:PlaceHolder>
</head>

其中我的css和js也在BundleConfig.vb中定义为:

bundles.Add(New ScriptBundle("~/bundles/jqueryPlus").Include(
            "~/Scripts/modernizr-{version}.js",
            "~/Scripts/jquery-{version}.js",
            "~/Scripts/jquery-ui-{version}.js",
            "~/ig_ui/js/infragistics.js",
            "~/Site.Master.js"))

bundles.Add(New StyleBundle("~/Content/MainContentCSS").Include(
                  "~/Content/Site.css",
                  "~/Content/Site-overrides.min.css",
                  "~/Content/rs-custom-controls.min.css",
                  "~/ig_ui/css/structure/infragistics.css",
                  "~/Examiner/Claim.master.min.css"))

并呈现为:

<link href="/Content/Site.css" rel="stylesheet"/>
<link href="/Content/Site-overrides.min.css" rel="stylesheet"/>
<link href="/Content/rs-custom-controls.min.css" rel="stylesheet"/>
<link href="/ig_ui/css/structure/infragistics.css" rel="stylesheet"/>
<link href="/Examiner/Claim.master.min.css" rel="stylesheet"/>
<script src="/Scripts/jquery-2.1.3.js"></script>
<script src="/Scripts/jquery-ui-1.11.2.js"></script>
<script src="/Scripts/modernizr-2.8.3.js"></script>
<script src="/ig_ui/js/infragistics.js"></script>
<script src="/Site.Master.js"></script>