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

@{Html.Telerik().ScriptRegistrar().Render();} Why do <script /> tags renders before <html>

3 Answers 204 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.
David
Top achievements
Rank 1
David asked on 02 Jun 2011, 02:11 AM
I'm new to Razor syntax and telerik MVC, but I am trying to get telerik controls to register the required javascript for a menu control using the following:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
@(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.min.css").Add("telerik.vista.min.css")))
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
</head>
<body>
    @RenderBody()
     
    <!-- NOTE: Should render required JavaScript for view page -->
    @{Html.Telerik().ScriptRegistrar().Render();}
</body>
</html>

The out put is in the wrong location, it is is comming out before the HTML node and so the menu which looks great, does not actually work

<script type="text/javascript" src="/Scripts/2011.1.315/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="/Scripts/2011.1.315/telerik.common.min.js"></script>
<script type="text/javascript" src="/Scripts/2011.1.315/telerik.menu.min.js"></script>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function(){
jQuery('#Menu').tMenu();});
//]]>
</script><!DOCTYPE html>
 
<!-- NOTE: The script has written before the HTML tag -->
<html>
<head>
    <meta charset="utf-8" />
    <title>Administrator Home</title>
    <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
 
<link type="text/css" href="/Content/2011.1.315/telerik.common.min.css" rel="stylesheet"/>
<link type="text/css" href="/Content/2011.1.315/telerik.vista.min.css" rel="stylesheet"/>
 
 
    <script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
</head>
<body>
     
<ul class="t-widget t-reset t-header t-menu" id="Menu"><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/mvc.png" />ASP.NET MVC<span class="t-icon t-arrow-down"></span></span><ul class="t-group"><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Mvc/Grid.png" />Grid</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Mvc/Menu.png" />Menu</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Mvc/PanelBar.png" />PanelBar</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Mvc/TabStrip.png" />TabStrip</span></li></ul></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/sl.png" />Silverlight<span class="t-icon t-arrow-down"></span></span><ul class="t-group"><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Sl/GridView.gif" />GridView</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Sl/Scheduler.gif" />Scheduler</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Sl/Docking.gif" />Docking</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Sl/Chart.gif" />Chart</span></li><li class="t-item t-state-default"><a class="t-link" href="http://www.telerik.com/products/silverlight.aspx">... and 28 more!</a></li></ul></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/ajax.png" />ASP.NET AJAX<span class="t-icon t-arrow-down"></span></span><ul class="t-group"><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Ajax/Grid.png" />Grid</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Ajax/Editor.png" />Editor</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Ajax/Scheduler.png" />Scheduler</span></li><li class="t-item t-state-default"><a class="t-link" href="http://www.telerik.com/products/aspnet-ajax.aspx">... and 28 more!</a></li></ul></li><li class="t-item t-state-default"><a class="t-link" href="#Menu-4"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/orm.png" />OpenAccess ORM<span class="t-icon t-arrow-down"></span></a><ul class="t-group"><li class="t-item"><div class="t-content" id="Menu-4">
 
                    <img src="/Content/Common/orm-comparison.png " alt="Telerik OpenAccess" />
                    <a id="buy" href="http://www.telerik.com/purchase/individual/orm.aspx">
                        Telerik OpenAccess ORM
                    </a>
                    <a id="express" href="http://www.telerik.com/community/license-agreement.aspx?pId=639">
                        Telerik OpenAccess ORM Express
                    </a>
                </div></li></ul></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/rep.png" />Reporting</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/sitefinity.png" />Sitefinity ASP.NET CMS</span></li><li class="t-item t-state-default" style="border-right: 0;"><span class="t-link">Other products<span class="t-icon t-arrow-down"></span></span><ul class="t-group"><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/test.png" />Web Testing Tools</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/win.png" />WinForms UI Controls</span></li><li class="t-item t-state-default"><span class="t-link"><img alt="image" class="t-image" src="/Content/Common/Icons/Suites/wpf.png" />WPF UI Controls</span></li></ul></li></ul>
 
</body>
</html>

3 Answers, 1 is accepted

Sort by
0
Pavol
Top achievements
Rank 1
answered on 16 Jun 2011, 01:28 PM
I had exactly the same problem. Because Scripts are shown before <html .. I have problem with menus and so on.

It is some way, how we can define where exactly will be scripts render inside the html ?
0
Atanas Korchev
Telerik team
answered on 16 Jun 2011, 01:57 PM
Hi,

 This is caused by a bug which we have fixed in the Q1 2011 SP1. However service packs are available only to users with commercial license. The workaround is not to use the Render method of the ScriptRegistrar:

@(Html.Telerik().ScriptRegistrar())

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
0
Chris
Top achievements
Rank 1
answered on 02 Aug 2011, 04:22 PM
I experienced the same problem (we're using 2010 Q3 right now) and the posted workaround didn't work.

I was able to work around the bug by doing the following:

@(MvcHtmlString.Create(Html.Telerik().ScriptRegistrar().ToHtmlString()))
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Pavol
Top achievements
Rank 1
Atanas Korchev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or