Is there a way to test if a bundle exists before trying to render it?
I want to do something like this:
@{
var bundleName = GetBundleName();
}
@if (Scripts.BundleExists(bundleName))
{
@Scripts.Render(bundleName)
}
Obviously, Scripts.BundleExists()
isn't real, but it there something build in that does this? Or do I have to implement this myself?
You can get the bundles in the View by:
var bl = System.Web.Optimization.BundleTable.Bundles;
Then you can search the collection for a specific bundle by path as registered in BundleConfig. After that check if the path or any of the included paths exist.