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

[Solved] ScriptRegistrar and Razor duplicating output issue

1 Answer 182 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.
Ed
Top achievements
Rank 1
Ed asked on 18 Feb 2011, 11:03 AM
Please correct me if I am mistaken, but I understand that ScriptRegistrar (SR) handles merging by using the .render() call only once, usually in the master page. However, when using the razor view engine, render is never used so what is happening is that each call to SR outputs an identical set of files rather than merging them. This is obviously undesirable behavior as it wastes bandwidth and defeats the purpose of SR.

How can I get merging to work using the razor view engine?

Added to global.asax to change default location:
  // set telerik default paths for scripts and styles
            WebAssetDefaultSettings.ScriptFilesPath = "~/public/js/t";
            WebAssetDefaultSettings.StyleSheetFilesPath = "~/public/css/t";

in web.config:
  <!-- validation-->
        <add name="v" combined="false" compress="false" enabled="true">
          <items>
            <add source="~/public/js/jquery.validate.min.js"/>
            <add source="~/public/js/jquery.validate.unobtrusive.min.js"/>
          </items>
        </add>

I have this is my master page:
  @( Html.Telerik().ScriptRegistrar())

and this in my view:
@(Html.Telerik().ScriptRegistrar()
     .Scripts(s => s.AddSharedGroup("v")))

Then I run the view and view source. This is the result, a duplication rather than a merge

<script type="text/javascript" src="/public/js/t/2010.3.1318/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/public/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="/public/js/jquery.validate.unobtrusive.min.js"></script>



       <!-- other content -->
    <script type="text/javascript" src="/public/js/t/2010.3.1318/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/public/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="/public/js/jquery.validate.unobtrusive.min.js"></script>

  </body>

1 Answer, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 18 Feb 2011, 11:05 AM
Hello Ed,

 Use this in your view (which will not render)

@{ Html.Telerik().ScriptRegistrar() .Scripts(s => s.AddSharedGroup("v")); }

Regards,
Atanas Korchev
the Telerik team
Tags
General Discussions
Asked by
Ed
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or