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)

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
@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)
it seems I acciently underestimated the power of "casette". thanks for answers. that helps me alot.
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.

1 Comment

to look an answer in current standards: yes its not possible but: "casette" is great . solved this issue flawlessly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.