PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/getting-started/using-kendo-with/aspnet-mvc/migration/migrating-from-telerik-extensions-for-aspnet-mvc.md

https://github.com/petar-raykov-telerik/kendo-docs
Markdown | 238 lines | 156 code | 82 blank | 0 comment | 0 complexity | 3d08f04c8a1ddc2e1108941c0d3270e6 MD5 | raw file
  1. ---
  2. title: Migrating to Kendo UI
  3. slug: mvc-migrating-from-extensions-to-mvc
  4. publish: true
  5. ---
  6. # Migrating from Telerik Extensions for ASP.NET MVC
  7. Kendo UI Complete for ASP.NET MVC contains many differences from Telerik Extensions for ASP.NET MVC. Some of these will be breaking changes.
  8. This document is meant to highlight these, as well as provide a general overview of issues that might occur when migrating from the
  9. Telerik Extensions for ASP.NET MVC to Kendo UI Complete for ASP.NET MVC.
  10. Keep in mind that due to the larger changes in terms of assembly name and namespaces, both the Telerik Extensions for ASP.NET MVC and Kendo UI Complete for ASP.NET MVC
  11. can be used in the same project, side-by-side. This allows developers to migrate an application component-by-component, without the need to immediately remove all of the
  12. Telerik Extensions components.
  13. Below you will find the major changes coming from Kendo UI Complete for ASP.NET MVC. Each change marks a difference between Kendo UI and the Telerik Extensions for ASP.NET MVC.
  14. For each one there will be a quick summary of the change, as well as a detailed description of the modifications.
  15. ## General Information
  16. ### Assembly Name
  17. _The change_: The name of the assembly that should be included in your project is *Kendo.Mvc.dll*
  18. With the Telerik Extensions for ASP.NET MVC the assembly that is included with each project is Telerik.Web.Mvc.dll. As Kendo UI Complete for ASP.NET MVC is not the same binaries, the new Kendo.Mvc.dll assembly will have to be referenced in your project.
  19. ### Namespace
  20. _The change_: The root namespace of Kendo UI Complete for ASP.NET MVC is *Kendo.Mvc.UI*
  21. The root namespace for the Telerik Extensions for ASP.NET MVC has been Telerik.Web.Mvc.
  22. With Kendo UI Complete for ASP.NET MVC the namespace will be different, namely Kendo.Mvc.UI.
  23. This means that any usage of the old namespace, such as using statements, will have to be updated.
  24. ### Web.config
  25. _The change_: The import statement in the web.config file should be importing *Kendo.Mvc.UI*
  26. With the Telerik Extensions for ASP.NET MVC the import statement found within the web.config refered to Telerik.Web.Mvc.UI
  27. . In order to take use of Kendo UI Complete for ASP.NET MVC an import statement importing Kendo.Mvc.UI will be needed instead.
  28. ### ASP.NET MVC version support
  29. _The change_: Kendo UI Complete for ASP.NET MVC supports ASP.NET MVC 3 and 4
  30. Previously the Telerik Extensions offer support for ASP.NET 1, 2, and 3.
  31. With Kendo UI Complete for ASP.NET MVC the versions of ASP.NET MVC that are supported are 3 and 4.
  32. The conclusion of which versions of ASP.NET MVC to support came from an investigation and discussion about our client-base's
  33. and industry adaptation of the newer versions of ASP.NET MVC. Additionally, support for only the latest two versions of ASP.NET MVC offer
  34. additional opportunities to implement features unable to be implemented in older versions of ASP.NET MVC.
  35. In order to take use of Kendo UI Complete for ASP.NET MVC all projects utilizing ASP.NET 1 or 2 will have to upgrade to 3 or 4.
  36. ### ScriptRegistrar and StyleSheetRegistrar
  37. _The change_: Kendo UI Complete for ASP.NET MVC will *not* take use of the ScriptRegistrar and StylesheetRegistar
  38. Traditionally with the Telerik Extensions for ASP.NET MVC every view containing Telerik components needed a ScriptRegistrar and a StylesheetRegistar,
  39. which respectively helped compress and combine scripts and style sheets. With Kendo UI Complete for ASP.NET MVC these are no longer required, nor used.
  40. The same GZIP compression that both the registrars utilize can be implemented on the web server level.
  41. As for bundling we offer a custom builder tool for the JavaScript files used with Kendo UI Complete for ASP.NET MVC and additionally ASP.NET 4.5 offers built-in bundling.
  42. ### Localization
  43. _The change_: Currently Kendo UI Complete for ASP.NET MVC is localized via satellite assemblies.
  44. The Telerik Extensions for ASP.NET MVC are localized via RESX files whereas Kendo UI Complete for ASP.NET MVC offers satellite assemblies. Individual messages can be easily
  45. overriden via configuration settings.
  46. ## Data-Binding
  47. ### Ajax Binding
  48. _The change_: Due to the usage of the Kendo UI DataSource component, Ajax binding in Kendo UI Complete for ASP.NET MVC is done in the following way (Grid component used as an example):
  49. @(Html.Kendo().Grid<Product>()
  50. .Name("Grid")
  51. .DataSource(dataSource => dataSource
  52. .Ajax()
  53. .Read(read => read.Action("AjaxBinding_Read", "Grid"))
  54. )
  55. )
  56. The Telerik Extensions for ASP.NET MVC follow the following convention for Ajax DataBinding
  57. @(Html.Telerik().Grid<Product>()
  58. .Name("Grid")
  59. .DataBinding(dataBinding => dataBinding
  60. .Ajax()
  61. .Select("AjaxBinding_Read", "Grid")
  62. )
  63. )
  64. As can be seen by comparing the two pieces of sample code above, the .DataBinding() statement has been replaced with .DataSource().
  65. Within the DataSource there are additional properties that need to be set. The most important ones are the .Read(), .Create(), .Update() and .Destroy() settings.
  66. These are, respectively, in place of .Select(), .Insert(), .Update(), .Delete() found within the Telerik Extensions for ASP.NET MVC.
  67. All components relying on Ajax binding will have to replace their .DataBinding() statements with the new .DataSource().
  68. ## Client-Side
  69. ### JavaScript files to include
  70. _The change_: The JavaScript files associated with Kendo UI Complete for ASP.NET MVC are the files associated with the Kendo UI widgets (
  71. kendo.web.min.js, specific widget files, or a custom file build) as well as kendo.aspnetmvc.min.js
  72. The Telerik Extensions for ASP.NET MVC include JavaScript files for each individual component,
  73. as well as some of the components features (the Grids filtering JS file for example).
  74. With Kendo UI Complete for ASP.NET MVC the bare minimum is kendo.web.min.js, which contains Kendo UI-specific JavaScript,
  75. and kendo.aspnetmvc.min.js, which contains the MVC-specific parts of Kendo UI Complete for ASP.NET MVC.
  76. Alternatively, instead of kendo.web.min.js one can include the specific components JavaScript files from Kendo UI or
  77. even use the custom download builder tool to create a customized single JavaScript file.
  78. This means that these new JavaScript files have to be added to the project in order for Kendo UI Complete for ASP.NET MVC to function.
  79. ### Server-side code blocks
  80. _The change_: Server-side code blocks, such as the one below, in a WebForms view are no longer supported:
  81. .OnSelect(() => { %>
  82. function() { }
  83. <% });
  84. Within the Telerik Extensions for ASP.NET MVC there have been three ways of subscribing to a client-side event handler:
  85. 1. Using the event handler name
  86. .OnSelect("onSelect")
  87. <script>function onSelect() {}</script>
  88. 2. Server-side code block in the WebForms ViewEngine
  89. .OnSelect(() => { %>
  90. function() { }
  91. <% });
  92. 3. Inline templates for Razor ViewEngine:
  93. .OnSelect(@<text> function() {} </text>)
  94. With Kendo UI Complete for ASP.NET MVC the second approach, using the server-side code block within the WebFroms ViewEngine, is no longer supported.
  95. This is due to complications and limitations around the server-side code block due to utilization of Response.Write to add this JavaScript to the page.
  96. Fortunately the third approach, using Razor, takes a string-based approach which removes these limitations.
  97. If approach number two is currently implemented using WebForms the recommended for migration would be to use approach number one.
  98. ### ClientEvents is now Events.
  99. _The change_: In order to subscribe to client-side events when defining a Kendo UI component the .Events() property has to be utilized.
  100. The fluent, or chaining, API that was utilized with the Telerik Extensions for ASP.NET MVC used the .ClientEvents() property to bind to a client-side event as follows:
  101. .ClientEvents(events => events.OnSelect("select"))
  102. However, with Kendo UI Complete for ASP.NET MVC "ClientEvents" has just become "Events" so the statement above will now be:
  103. .Events(events => events.Select("select"))
  104. This also takes the new client-side event names (found below) into consideration. These changes will require all instances of .ClientEvents() will need to be
  105. replaced with the new .Events() property.
  106. ### Client-side event name changes
  107. _The change_: Kendo UI Complete for ASP.NET MVC will not have the prefix of "On" in front of each of the client-events e.g. "OnChange" is now "Change"
  108. When subscribing to client-side events the Telerik Extensions for ASP.NET MVC used names such as OnLoad, OnChange, OnDataBound etc., but all "On" prefixes are removed with Kendo UI Complete for ASP.NET MVC. So all event subscriptions will have to remove the "On" prefix as follows:
  109. .Events(events => events.OnChange("foo"))
  110. becomes
  111. .Events(events => events.Change ("foo"))
  112. ### The client-side OnLoad event has been removed
  113. _The change_: With Kendo UI Complete for ASP.NET MVC the OnLoad event has been removed. Developers should utilize the documents ready event instead.
  114. The OnLoad event found within the Telerik Extensions for ASP.NET MVC gets raised when a UI component is initialized. However, in terms of the pages lifecycle this essentially occurs right at the same time as the documenys ready event and for the sake of efficiency, the support for OnLoad was dropped from Kendo UI Complete for ASP.NET MVC. This means that all usages of .OnLoad() will have to be placed within a function that handles documents ready event:
  115. .OnLoad("onLoad")
  116. becomes
  117. $(document).ready(function () { onLoad(); });
  118. ### Client-side events are now Kendo events instead of jQuery events
  119. _The change_: In an attempt to limit event bubbling in order to optimize the components, Kendo UI Complete for ASP.NET MVC utilize Kendo events instead of jQuery events.
  120. Many jQuery events traditionally bubble up from the target element all the way to the document root.
  121. The Telerik Extensions for ASP.NET MVC offer all of its client-side events as jQuery events, which means many of these events will trigger event bubbling.
  122. Kendo UI utilizes its own type of events, which do not create the same event bubbling effect, which are utilized within Kendo UI Complete for ASP.NET MVC.
  123. This will require all scenarios where event bubbling is either implemented or taken for granted will have to be modified to adhere to the new Kendo-style events.
  124. ### Retrieving the client-side object
  125. _The change_: Kendo UI Complete for ASP.NET MVC utilizes a similar approach to traditional Kendo UI when retrieving the components client-side object: `$("#foo").data("kendoGrid")` (with the Grid as an example).
  126. With the Telerik Extensions for ASP.NET MVC the client-side object of a Grid was retrieved in the following way:
  127. var grid = $("#foo").data("tGrid")
  128. However, with Kendo UI Complete for ASP.NET MVC the proper way to grab the client-side object is:
  129. var grid = $("#foo").data("kendoGrid")
  130. This change will require all instances of grabbing the client-side object to be changed to follow the Kendo UI Complete-specific convention.
  131. ### Client-side event binding
  132. _The change_: With Kendo UI Complete for ASP.NET MVC binding to an event on the client-side looks like:
  133. var grid = $("#foo").data("kendoGrid");
  134. grid.bind("dataBound");
  135. Traditionally with the Telerik Extensions for ASP.NET MVC one had to do the following to bind to a client-side event in JavaScript:
  136. $("#foo").bind("dataBound");
  137. However, with the usage of Kendo UI events this will no longer work with Kendo UI Complete for ASP.NET MVC.
  138. The new required approach is to first get an instance of the components client-side object, then utilize the bind function found within this object.
  139. ### Themes and Stylesheets
  140. By default, Kendo UI Complete for ASP.NET MVC uses the Kendo UI stylesheets.
  141. Similar to the Telerik Extensions for ASP.NET MVC, the Kendo UI widgets use a base stylesheet (kendo.common.css) and a theme-specific stylesheet (kendo.[theme_name].css),
  142. both of which should be registered manually on the page. The base stylesheet should be registered before the theme stylesheet,
  143. because the theme might need to override some of the base styles.
  144. The Kendo UI widgets come with the following themes: Black, BlueOpal, Default, Metro (Green) and Silver.
  145. The styling mechanism of the MVC extensions and the Kendo UI widgets is quite similar.
  146. More information about the Kendo UI styling is available in the [Kendo UI Appearance and Styling](http://docs.kendoui.com/getting-started/web/appearance-styling) documentation article.
  147. In some cases, developers that migrate from Telerik Extensions for ASP.NET MVC to Kendo UI Complete for ASP.NET MVC, may want to preserve the previous look of the components.
  148. For this purpose the so-called **legacy themes** are provided.
  149. They represent modified versions of the MVC extensions' stylesheets, so that they are compatible with the Kendo UI widgets.
  150. Changes include changing the classnames' prefix from "t-" to "k-", and some tweaks required by the slightly different HTML output of the Kendo UI widgets.
  151. Note that **using Kendo UI stylesheets and legacy themes on the same page is not supported**.
  152. Generally, it is encouraged to use the Kendo UI themes, not the legacy ones.
  153. The latter are located in the **wrappers/aspnetmvc/LegacyThemes** folder of the Kendo UI Complete for ASP.NET MVC distribution package.
  154. Legacy themes can also be referenced from the Kendo UI CDN. Don't forget to specify the version (e.g. 2012.2.710)
  155. <link href="http://cdn.kendostatic.com/<VERSION>/styles/telerik/telerik.common.min.css" rel="stylesheet" type="text/css" />
  156. <link href="http://cdn.kendostatic.com/<VERSION>/styles/telerik/telerik.black.min.css" rel="stylesheet" type="text/css" />