2

I want to use:

<%:  System.Web.Optimization.Scripts.Render("~/bundles/MyBundle") %>

in .ascx file. There is no problem when i am loading scripts to body. However, i don't know, how to include this script to <head> of my .aspx file. Any ideas? I cannot do this from code behind.

2 Answers2

1

<head> <script src=<%= Page.ResolveClientUrl(~/bundles/MyBundle") %> type=text/javascript></script> </head> You can use this to include in your .aspx page

Hamza Haider
  • 730
  • 6
  • 20
0

Microsoft.Web.Optimization is now obsolute. With MVC 4, you can use Microsoft Asp.Net web optimization framework.

You can install It from a NuGet package:

After installation, configure bundle(s) in App_Start\BundleConfig.cs:

bundles.Add(new ScriptBundle("~/Scripts/jquery").Include(
            "~/Scripts/Lib/jquery/jquery-{version}.js",
        "~/Scripts/Lib/jquery/jquery.*",
        "~/Scripts/Lib/jquery/jquery-ui-{version}.js")
    );

More information on how to configure and use it here:

How to add reference to System.Web.Optimization for MVC-3-converted-to-4 app

Gauravsa
  • 6,330
  • 2
  • 21
  • 30