[英]Is there a way to “un-render” a bundle of JavaScript files?
Currently, we are bundling Bootstrap files like this: 目前,我们正在捆绑这样的Bootstrap文件:
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: 然后,我们使用以下命令将这些捆绑包应用于HTML文件:
@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. 但是,我们希望不再逐步使用Bootstrap,因为我们已经加入了不想使用Bootstrap的UX / UI专家。
Is there any way to undo the @Scripts.Render command or to apply Bootstrap to only a specific portion of a view? 有什么方法可以撤消@ Scripts.Render命令或仅将Bootstrap应用于视图的特定部分? Is the @Scripts.Render command inherited by all child partial views? @ Scripts.Render命令是否被所有子局部视图继承?
What @Stephen Muecke commented is absolutely correct. @Stephen Muecke评论的是绝对正确的。 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? 有什么方法可以撤消@ Scripts.Render命令或仅将Bootstrap应用于视图的特定部分?
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? @ Scripts.Render命令是否被所有子局部视图继承?
Yes. 是。
This is what you can do. 这就是您可以做的。
We did this for conditional loading. 我们这样做是为了有条件的加载。 We added a flag in ViewBag. 我们在ViewBag中添加了一个标志。
ViewBag.isBootStrapRequired = true;
In the layout page, we loaded the bundle like this. 在布局页面中,我们这样加载了包。
if(ViewBag.isBootStrapRequired) {
@Scripts.Render("~/bundles/bootstrap")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.