Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control Kendo Script Position Rendering in MVC

I'm using the Kendo ASP.NET MVC wrappers. I noticed the wrappers are rendering the scripts to initialize the controls immediately after the control markup. Is there a way to configure to have the scripts render at the bottom? Before, with the Telerik ASP.NET MVC controls, you could have the script manager render all the initializations at the bottom. Is that possible?

like image 807
Brian Mains Avatar asked Mar 09 '13 14:03

Brian Mains


3 Answers

In the 2013 Q1 release, they added support for deferred scripts. You can use it like so:

@(Html.Kendo().AutoCompleteFor(m => m)
    .Filter(FilterType.Contains)
    .MinLength(2)
    .DataSource(config =>
        {
            config.Read(action, controller, routeValues);
            config.ServerFiltering(true);
        }).Deferred())

Note the Deferred() method in the end of the chain. Then, in your layout add the following anywhere in your markup:

  <!-- ... -->
  @Html.Kendo().DeferredScripts()
  </body>
</html>

See http://www.kendoui.com/forums/mvc/general-discussions/kendo-initialization-scripts-in-body-interfere-with-other-libraries.aspx for more information.

like image 112
jrummell Avatar answered Oct 14 '22 17:10

jrummell


This would be a bit of a headache, but since the wrappers generate jQuery script couldn't you generate the wrapper in a partial view, grab the resulting script and inject it into a script tag at the bottom of your page? Of course, that would mean either duplicated code or a fair amount of code to generate the workaround in a reusable way, all so the scripts end up at the bottom of the page instead of the middle.

I'm assuming this is to help with performance (best practice generally being to put your CSS at the top and scripts at the bottom)?

like image 32
Elsimer Avatar answered Oct 14 '22 17:10

Elsimer


I am sorry this is not possible and could not be work-arounded. The scripts of the Kendo Wrappers for MVC are always rendered after the html wrapper of the widget.

It is mentioned in the documentation.

EDIT: This is later on possible with the deferred scripts rendereding that jrummell exiplained.

like image 27
Petur Subev Avatar answered Oct 14 '22 16:10

Petur Subev