3

Attempting to use css and js files with same virtualpath bundle name
1 - is it possible ? (tried:but failed. cant define same virtual path name both for script and style)
2 - it it possible to builtup a ScriptAndStyleBundle together included with a mixed bundle ?

Just because I wantto use same name both for css and js.

//in BundleConfig.cs
bundles.Add(new ScriptBundle("~/bundles/doMenu")
            .Include("~/Plugins/doMenu/files/js/doMenu.js")
            );

        bundles.Add(new StyleBundle("~/bundles/doMenu")
            .Include("~/Plugins/doMenu/files/css/doMenu.css")
            );

//in _PartialLayoutMenu.cs
@Scripts.Render("~/bundles/doMenu")
@Styles.Render("~/bundles/doMenu")


result is:
<!--MENU LAYOUT-->
<script src="/Plugins/doMenu/files/css/doMenu.css"></script>

<link href="/Plugins/doMenu/files/css/doMenu.css" rel="stylesheet"/>
<!--/MENU LAYOUT-->

any clue ? or I want such a useless mind ?(thanks)

Zen Of Kursat
  • 2,672
  • 1
  • 31
  • 47

2 Answers2

3

Bundle names should be unique within the both styles and scripts. And since they are entirely different types you cannot mix them into a single bundle because then you wouldn't know how to reference it in the DOM: whether you should use a <script> or a <style> tag. Unfortunately what you are asking for is not possible.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
3

I'm using Cassette, which does support this feature.

Configuration:

bundles.Add<ScriptBundle>(BundleNames.Grid,
                          new[] {"~/Scripts/Grid.js"},
                          bundle => bundle.AddReference("~/" + BundleNames.Base));

bundles.Add<StylesheetBundle>(BundleNames.Grid,
                              new[] {"~/Content/Grid.less"});

BundleNames is a helper class I have with constant strings.

Reference bundles in views:

@{
    Bundles.Reference(BundleNames.Grid);
}

As you'd expect, this will include all CSS and JS, in the correct order.

I'd also mention that I've started using Cassette before ASP.Net had bundle management and I'm very happy with it. I didn't find any interesting feature ASP.Net had that I'm missing.

Kobi
  • 135,331
  • 41
  • 252
  • 292
  • I render bundle in PartialLayout, and calling it @Html.Partial("_Menu")thus it doesnt put css link into header section.I read about this issue solved by casette can do it? but this is another question. – Zen Of Kursat Apr 26 '15 at 08:34
  • @N.Ramos - Yes, Cassette can handle that easily - it is designed for that. It makes sure each bundle is only included once, and they are all in the right order. Actually, I'd be very disappointed without this feature, I use it a lot (for example, a partial view that requires MathJax or DropzoneJS) – Kobi Apr 26 '15 at 08:55
  • it seems I acciently underestimated the power of "casette". thanks for answers. that helps me alot. – Zen Of Kursat Apr 26 '15 at 09:14