Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing other bundles in BundleConfig.cs in ASP.NET MVC4 app

I am working on an MVC4 application where I'm using WebOptimization to do all of my resource handling (cat and min). I have a few pages which are very similar, but need a few varying styles on a page by page basis.

So, I am trying to reference one bundle (base styles) within another bundle (page specific styles) and I'm not having much luck. Here's what I have in my bundle config:

bundles.Add(new StyleBundle("~/bundles/css/search").Include(
  "~/Content/css/partials/grid-controls.css",
  "~/Content/css/partials/grid.css",
  "~/Content/css/views/search.css"));

bundles.Add(new StyleBundle("~/bundles/css/searchtrees").Include(
  "~/bundles/css/search",
  "~/Content/css/views/search/trees.css"));

On the search trees page I get the trees.css but nothing from the base search CSS bundle.

How can I go about referencing the first bundle in the second? I'm sure there's a way, just not too familiar with bundling yet.

like image 544
jasonmerino Avatar asked May 10 '13 16:05

jasonmerino


1 Answers

You can reuse the file references instead of referencing another bundle. Something like this:

var baseIncludes = new string [] { "~/Content/css/partials/grid-controls.css", "~/Content/css/partials/grid.css", "~/Content/css/views/search.css" };

// 'base' bundle references the base includes
bundles.Add (new StyleBUndle ("~/bundles/css/search").Include (baseIncludes));

// other bundle references the base includes and some extras
bundles.Add (new StyleBundle ("~/bundles/css/searchtrees").Include(baseIncludes).Include ("~/Content/css/views/search/trees.css"));
like image 57
mkorman Avatar answered Nov 24 '22 09:11

mkorman