This is a migrated thread and some comments may be shown as answers.

ScriptRegistrar() Confusion...

1 Answer 153 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andreas
Top achievements
Rank 1
Andreas asked on 29 Jun 2011, 04:12 PM
Hello,

I just started using telerik ASP.NET MVC and I must admit that I am impressed.  However, I am struggling with proper usage of ScriptRegistrar() in MVC3 using Razor.  I have this in my _Layout.cshtml:

@(Html.Telerik().ScriptRegistrar().DefaultGroup(group =>
                           group.Add("jquery-1.5.1.min.js")
                              .Add("modernizr-1.7.min.js")
                                .Add("telerik.common.min.js"))
 )

In my Index.cshtml, which I use for testing, I have this:

@{ Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Add("telerik.panelbar.min.js")); }

The rendered result is this:

<script type="text/javascript" src="/Scripts/jquery-1.5.1.js"></script>
<script type="text/javascript" src="/Scripts/2011.1.315/telerik.panelbar.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="/Scripts/modernizr-1.7.min.js"></script>
<script type="text/javascript" src="/Scripts/2011.1.315/telerik.common.min.js"></script>

Please note the position of the telerik.panelbar.min.js file in the list.  The result is a non functioning PanelBar.  If I remove my ScriptRegistrar() call in the Index.cshtml file and rely on the auto-config of PanelBar the PanelBar JavaScript appears at last in the list and it works.

Even more confusing it becomes when I use the .Combine(true) feature.  Adding this to the two samples above will result in a non functioning PanelBar control.

I also tried using Script groups.  When adding .Combine(true) to the default group but not to the custom group containing the PanelBar scripts ended in output where I can see the combined default group followed by the single PanelBar script include.  Result: PanelBar did not work.

During my research I found a 'AssetKey' property I can set.  But the docs don't tell me what it is good for or how to use it.  My guess is that it somehow deals with WebAsset handling.

Maybe it is just my personal stupidity, but with the given documentation I am not able to use the ScriptRegistrar feature effectively.  Can you please point me to samples that illustrate this issue in more depth or provide more in depth documentation?

Thanks a lot in advance!
Andreas

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 30 Jun 2011, 09:02 AM
Hello Andreas,

 The problem is that telerik.panelbar.min.js depends on other files as outlined in the Required JavaScript files help topic. The ScriptRegistrar from the view page comes first during rendering thus the panelbar script is rendered first. You need to register the other files on which telerik.panelbar.min.js depends.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Andreas
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or