c# - ASP.NET MVC 5 bundled scripts not being called in _Layout.cshtml -


before start let me know there other questions on issues have great answers please let me explain how mine different.

i have asp.net mvc 5 project have collection of bundles:

public class bundleconfig {     // more information on bundling, visit http://go.microsoft.com/fwlink/?linkid=301862     public static void registerbundles(bundlecollection bundles)     {         bundles.add(new scriptbundle("~/bundles/jquery").include(                     "~/scripts/jquery.js"));          bundles.add(new scriptbundle("~/bundles/jqueryval").include(                     "~/scripts/jquery.validate*"));          // use development version of modernizr develop , learn from. then, when you're         // ready production, use build tool @ http://modernizr.com pick tests need.         bundles.add(new scriptbundle("~/bundles/modernizr").include(                     "~/scripts/modernizr-*"));           bundles.add(new scriptbundle("~/bundles/bootstrap").include(             "~/scripts/bootstrap.js"));          bundles.add(new stylebundle("~/content/css").include(                   "~/content/bootstrap.css",                   "~/content/freelancer.css"));          // plugin javascript         bundles.add(new scriptbundle("~/bundles/pluginjs").include(                 "~/scripts/cbpanimatedheader.js",                 "~/scripts/classie.js"));          //custom theme js         bundles.add(new scriptbundle("~/bundles/customthemejs").include(                     "~/scripts/freelancer.js"));          // contact form javascript         bundles.add(new scriptbundle("~/bundles/contactvalidation").include(                   "~/content/jqbootstrapvalidation.js",                   "~/content/contact_me.js"));     } 

these called in _layout.cshtml:

    @scripts.render("~/bundles/customthemejs")     @scripts.render("~/bundles/jquery")     @scripts.render("~/bundles/contactvalidation")     @scripts.render("~/bundles/pluginjs")     @scripts.render("~/bundles/bootstrap")     @rendersection("scripts", required: false)    </body> </html> 

and in `global.asax:

protected void application_start()     {         arearegistration.registerallareas();         filterconfig.registerglobalfilters(globalfilters.filters);         routeconfig.registerroutes(routetable.routes);         bundleconfig.registerbundles(bundletable.bundles);     } 

here know far:

  1. all stylebundle's called , invoked can pin point problem within script referencing
  2. the scripts referred in correct folder i.e ~/scripts/.... know isn't referencing issue.
  3. the scripts working have tested them using web forms project
  4. i have tried referencing bundles in head section of _layout.cshtml no change
  5. dev tools in chrome , debugger in vs show the script not being run
  6. my suspicion there gap somewhere between call _layout.cshtml , bundles in bundleconfig class

i have tried other solutions others have recommended around web such looking syntax errors etc... far aware there none.

to make structure of scripts obvious have included screen shot: enter image description here

can see in different perspective myself , see have gone wrong?

your code looks correct, though referencing microsoft.web.optimization application config may not working correctly. can force reference application utilize web.optimization. inside of _layout.cshtml above bundled data, place following:

@using system.web.optimization 

that should correctly enforce web.optimization.

the other part may wrong, can't see global.asax. need ensure call registerbundle.

bundleconfig.registerbundle(bundletable.bundles); 

Comments