Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET MVC > General Discussions > In the ScriptRegistrar, what are the use of groups?

Not answered In the ScriptRegistrar, what are the use of groups?

Feed from this thread
  • Gordon avatar

    Posted on Feb 5, 2012 (permalink)

    I'm relatively new to the ScriptRegistrar and how it works, and I'm impressed with what I've seen so far. I just wanted to ask though, what are the point of groups? Do they do anything special?

    I thought perhaps you could specify groups in the layout and enable them on views as necessary, but this does not appear to be the case (from what I can find). So what is the practical use of groups?
    -------------------------
    EDIT
    It turns out you can enable and disable groups on views, I just didn't see this before. Also, it does not work in partials, which is where I wanted to use it.

    For reference, this is how I'm enabling and disabling groups:
    In _Layout.cshtml:
    @Html.Telerik().ScriptRegistrar().Scripts(scripts => scripts
        .AddGroup("Group1", group => group
            .Add("...") //etc
            .Enabled(false)
        ).AddGroup("Group2", group => group
            .Add("...") //etc
            .Enabled(false)
        )
    )
    @RenderSection("head", required: false);
    
    In my View.cshtml:
    @section head {
        @Html.Telerik().ScriptRegistrar().Scripts(scripts => scripts
            .GetGroup("Group1", group => group.Enabled(true))
            .GetGroup("Group2", group => group.Enabled(true))
        )
    }
    It's pretty awesome how it works.

    However, if I cut the code from the view and paste it into a partial, that doesn't work. At all.
    So my question is now, how can I enable script groups in a partial?
    -------------------
    Edit again
    The view code above actually renders a new set of scripts, so I've got all my base scripts rendered twice. I tried enclosing it in curly braces, so it doesn't render at that point, but it doesn't include the groups in the ScriptRegistrar on the layout. In short, it doesn't work.
    On a side note, I had to put the code into that "head" section or else it crashes because it doesn't know about those groups.

    So I'm back to my original questions: How can I enable / disable script groups per view / partial, or what practical use are script groups?

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET MVC > General Discussions > In the ScriptRegistrar, what are the use of groups?