I’m setting up my MVC4 app to use the built-in ASP.Net bundling (converting from Squishit). I’ve set up the BundleConfig class, and things all work fine, but for cases where a Razor file only has a reference to one JavaScript file, I don’t see the need to involve that config file. I’d rather just add the script to the BundleTable right in my Razor ‘Scripts’ section, and Render it right there. That way I can do a release to production quite easily for small changes if I have to rather than change the BundleConfig file. This is what I have:
@section Scripts
{
@{
const string bundle = "~/bundles/{myVirtualBundlePath}";
BundleTable.Bundles.Add(new ScriptBundle(bundle)
.Include("{myActualJavaScriptFilePath}"));
Scripts.Render(bundle);
}
}
and while this builds ok, the reference to that bundled file never gets output to HTML.
Do I need to get a reference to the particular BundleCollection that the BundleConfig uses?
Only difference between mine (that works) is that I add the bundle outside of the script block. If this doesn’t work make sure it does work in the main bundle start-up, it could be some other issue.