javascript - Adding to script bundle from partial view in .NET MVC 5 -


We are creating a Net MVC websolution using the provided widget as HTML.Partials () . We have been the main page view scripts would like to be able to partially view to linking their dependence tags, both CSS files as well as JavaScript files

Part I tried with this code. But the JS-file is not provided in the layout section of my page. What is wrong? @ {var bundle = system. Web. Optimization. Bundleable.bundle.getRigestered bundle (). Where (b = & gt; b.path == "~ / bundle / jacquery") .First (); Bundle.Include ("~ / script / addtojquerybundletest.js"); }

It appears to be specific for my jquery bundle , I've added a widgetspace bundle, where you can add scripts to render in the main layout. The bundle also manages to add the same file multiple times (which can happen if the same widget exists multiple times on the same page) and renderes it only once. My solution was added below, which was well documented with searches till now.

In BundleConfig.cs:

  bundles Add (new scriptbundle ("~ / widgetspecific"));   

In _Layout.cshmtl:

  @ Scripts.Render ( "~ / widgetspecific")   

Widget .cshtml:

  @ {var bundle = system. Web. Optimization. Bundledable. Bundles: Getbundlefor ("~ / widgetspecific"); Bundle.Include ("~ / scripts / andreas.js"); }   

Is anyone aware of the negative aspects of this solution?

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -