Reputation: 2716
Currently, we are bundling Bootstrap files like this:
public class BundleConfig
{
// For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/Site.css"));
}
}
And we are applying these bundles to our HTML files using this command:
@Scripts.Render("~/bundles/bootstrap")
However, we are hoping to move away from using Bootstrap incrementally as we have onboarded a UX/UI expert who doesn't want to use Bootstrap.
Is there any way to undo the @Scripts.Render command or to apply Bootstrap to only a specific portion of a view? Is the @Scripts.Render command inherited by all child partial views?
Upvotes: 0
Views: 75
Reputation: 34137
What @Stephen Muecke commented is absolutely correct. I would like to add few more.
Is there any way to undo the @Scripts.Render command or to apply Bootstrap to only a specific portion of a view?
You cannot undo the rendered scripts. You cannot limit it to a specific portion of a view. And the rendered scripts will be applied to all partials.
Is the @Scripts.Render command inherited by all child partial views?
Yes.
This is what you can do.
We did this for conditional loading. We added a flag in ViewBag.
ViewBag.isBootStrapRequired = true;
In the layout page, we loaded the bundle like this.
if(ViewBag.isBootStrapRequired) {
@Scripts.Render("~/bundles/bootstrap")
}
Upvotes: 1