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? 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: In _Layout.cshmtl: Widget .cshtml: Is anyone aware of the negative aspects of this solution? @ {var bundle = system. Web. Optimization. Bundleable.bundle.getRigestered bundle (). Where (b = & gt; b.path == "~ / bundle / jacquery") .First (); Bundle.Include ("~ / script / addtojquerybundletest.js"); }
bundles Add (new scriptbundle ("~ / widgetspecific"));
@ Scripts.Render ( "~ / widgetspecific")
@ {var bundle = system. Web. Optimization. Bundledable. Bundles: Getbundlefor ("~ / widgetspecific"); Bundle.Include ("~ / scripts / andreas.js"); }
Comments
Post a Comment