renders ScriptBundle as css link elements

2019-04-30 22:34发布

问题:

I'm trying to use the new .net 4.5 webforms control to render bundles in my materpage. I have a scriptbundle defined in my BundleConfig.cs like this:

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"));

I then try to render the bundle using the new <webopt:BundleReference> control:

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

But when the page renders, the output is <link> tags, rather than tags:

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

Is this control meant to only render styles? Or am I doing something wrong? How can I render a script bundle using a webopt control and not the <%: Scripts.Render() %> syntax?

回答1:

I'm using VS2012 and .Net 4.5. I do npt use the webopt control. I render like this:

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

where my css and js are also defined in BundleConfig.vb as:

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

And renders as:

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