在C#MVC的单个捆绑包内添加多个捆绑包 [英] Add multiple Bundles inside a single Bundle in C# MVC

查看:115
本文介绍了在C#MVC的单个捆绑包内添加多个捆绑包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我要创建这样的捆绑包

For Example I Want to Create Bundles like this

/*These are my Two separate Bundles*/

bundles.Add(new StyleBundle("~/Content/MYBundle1").Include(
           "~/Content/css/style.css"));

bundles.Add(new StyleBundle("~/Content/MYBundle2").Include(
           "~/Content/css/media.css"));

/*Now i want to use above two bundles as a single bundle */

bundles.Add(new StyleBundle("~/Content/AllPageBundles").Include(
           "~/Content/MYBundle1",
           "~/Content/MYBundle2")

我还想问一问,我可以添加对任何站点服务器上实际存在的捆绑软件内的任何文件的引用吗? 例如:我想在捆绑包中添加Google字体文件,就像我写的波纹管

Also I want to ask that can i add reference of any file inside a bundle that is physically exist at any site server For Example:I want to add google fonts file inside a bundle like i write bellow

bundles.Add(new StyleBundle("~/Content/MYBundle1").Include(
               "http://fonts.googleapis.com/css?family=Open+Sans:300"));

推荐答案

对于多捆包,您可以这样写:

For multi-bundles you can write like:

对于目录:

 bundles.Add(new Bundle("~/js/core").IncludeDirectory(@"~/Scripts/Infrastructure/JQuery", "*.js")
                                                     .IncludeDirectory(@"~/Scripts/Infrastructure/Knockout", "*.js")
                                                     .IncludeDirectory(@"~/Scripts/Infrastructure", "*.js"));

对于文件:

 bundles.Add(
                new Bundle("~/js/kendo").Include("~/Scripts/kendo/kendo.core.min.js")
                                        .Include("~/Scripts/kendo/kendo.data.min.js")
                                        .Include("~/Scripts/kendo/kendo.binder.min.js")
                                        .Include("~/Scripts/kendo/kendo.calendar.min.js")

对于url,请尝试以下代码:

For url try this code:

var jqueryCdnPath = "http://fonts.googleapis.com/css?family=Open+Sans:300";
bundles.Add(new ScriptBundle("myfoobundle", jqueryCdnPath).Include("~/Scripts/jquery-{version}.js"));

这篇关于在C#MVC的单个捆绑包内添加多个捆绑包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆