I’ve been pretty quiet lately. Spent all my time on our big app, working with the usual MVC, DDD, nHibernate and the like. Much to our content, so far we have managed to keep up with the ever changing landscape of Dutch mental healthcare. For our webpages we were using the Telerik MVC suite, in a previous post I already shared some of our experiences. Telerik is replacing the MVC suite with the new Kendo suite. Which has several very appealing options. Besides that support on the MVC suite is coming to an end. Time to move on.
Replacing all components in one go was not possible. Kendo has the same architecture as the MVC suite and a very similar syntax. But our app is just to large to change all in one go. According to the documentation it’s possible to mix the two suites, even in the same view. To get that actually to work took an effort beyond the faq. In this post I’ll dive into the details.
Both MVC and Kendo require some style sheets. In the mvc suite you need a StyleSheetRegistrar component to render the css links. Kendo follows the standard way.
Registering the style sheets
When it comes to jQuery things get somewhat complicated. The MVC suite requires version <= 1.7, Kendo requires versions >= 1.9. These two are not compatible. Thank goodness the jquery-migrate script library patches the leaks, making it possible for the mvc suite to run using jquey 1.9. The gotcha is that the mvc suite uses a ScriptRegistrar component to register the Telerik scipts. By default this component will also register (the wrong version of) jQuery again. This is prevented by the jQuery(false) method of the registrar.
The MVC suite scripts should be rendered at the end of the page
To sum things up. The full master layout
In case your views use Ajax forms, rendered using Ajax.BeginForm, the ajax scripts are required. Imho these forms are a pita. The handling of events is quite entangling and, even worse, fields edited with a Kendo editor are not included the postdata. For most of our forms we do a straight post using extension methods. Alas, not all views have been adapted yet, so for now the scripts are still required. The good thing is that they still work in the new jquery scenario and don’t seem to bite anything else.
Using this layout both suites can be combined on one page. Here’s a Kendo Colorpicker used within an mvc tabstrip
The way the localization of the components work differs. Kendo is very much script based. For instance the titles of the buttons of the colorpicker above can only be set from script.
To standardize the look and feel of our components we build them using html extension methods, as described here. Also the Telerik Components, which have a lot of options which can be set. The Kendo suite has an Html extension library, the extension methods in there provide options to configure the component. Alas this list of options is not complete, it is smaller in than the list of configuration options from script. FI it is not possible to set the captions from the extension method for the colorpicker.
All html extension methods do is render some script. It is no great deal to bypass the Kendo extension methods and render the script yourself. The Kendo components all follow the same pattern
The main difference is that one component renders an input and the other a div.
To get all possibilities of configuration via script you can create your own extension methods which directly render the script
The captions are set to OK and annuleren. For now hard coded.
The NameBuilder method is the one from one of my previous stories. It is used to generate an unique id.
So far mixing Kendo and the classical suite works well. We had two small gotchas so far.
- Window stacking. In the mvc suite you can stack windows on top of each other. A popup in a popup, In the Kendo suite you can do that as well. This stacking is done using high z-index-es. The classical suite uses a higher range than Kendo. Resulting in a Kendo popup window launched from a classic window appearing behind it’s originator. You cannot stack Kendo and classical windows. Thanks goodness changing from classical window to Kendo window is no big deal.
- Ajax forms. As mentioned inputs using Kendo components will exclude the edited fields from the ajax postdata. In our app we are switching to posting the data straight from script, using our postdata extension. Far more flexible and no more need for a form.
Finding out the way the classical suite and Kendo require jQuery was somewhat of a hurdle. But now all works well and we can convert all further code at our pace. And please our users with a better look and feel. The way the Kendo window automatically adjusts to the size of it’s content is worth the migration on itself.