|
2 | 2 |
|
3 | 3 | ## Including the Client-Side Resources |
4 | 4 |
|
5 | | -Before you can use a Telerik UI component, you must include the theme, the jQuery script, and the Kendo UI scripts: |
| 5 | +To enable the Telerik UI for ASP.NET MVC components, you must add several [client-side]({% slug copyclientresources_aspnetmvc6_aspnetmvc %}) dependencies to the application, like scripts and a [theme file]({% slug sassbasedthemes_overview%}) |
6 | 6 |
|
7 | | -1. Go to `~\Views\Shared\_Layout.cshtml` and add the Kendo UI theme of your choice to the `<head>` of the document. Since Microsoft's project template uses Bootstrap, you can use the Kendo UI SASS Bootstrap theme to match it. |
| 7 | +Before adding a Telerik UI component, you must include the theme, the jQuery script, and the Kendo UI scripts: |
| 8 | + |
| 9 | +1. Go to `~\Views\Shared\_Layout.cshtml` and add the theme of your choice to the `<head>` of the document. Since ASP.NET Web Application template uses Bootstrap, you can use the [Telerik UI Bootstrap theme]({% slug sassbasedthemes_overview%}#built-in-themes) to match it: |
8 | 10 |
|
9 | 11 | ```HTML |
10 | 12 | <head> |
11 | | -<meta charset="utf-8" /> |
12 | | -<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
13 | | -<title>@ViewBag.Title - My ASP.NET Application</title> |
14 | | -@Styles.Render("~/Content/css") |
15 | | -@Scripts.Render("~/bundles/modernizr") |
16 | | - |
17 | | -@* Add the Kendo SASS Bootstrap theme: *@ |
18 | | -<link href="https://kendo.cdn.telerik.com/themes/{{ site.themesCdnVersion }}/bootstrap/bootstrap-main.css" rel="stylesheet" type="text/css" /> |
| 13 | +... |
| 14 | +@Styles.Render("~/Content/css") |
| 15 | +@Scripts.Render("~/bundles/modernizr") |
| 16 | + |
| 17 | +@* Add the Telerik UI Bootstrap Main theme: *@ |
| 18 | +<link href="https://kendo.cdn.telerik.com/themes/{{ site.themesCdnVersion }}/bootstrap/bootstrap-main.css" rel="stylesheet" type="text/css" /> |
| 19 | +... |
19 | 20 | </head> |
20 | 21 | ``` |
21 | 22 |
|
22 | | -1. In the `_Layout.cshtml` file, locate the `@Scripts.Render("~/bundles/jquery")` line in the `<body>` of the document and delete it. This jQuery script reference comes with the Microsoft ASP.NET Web Application template. |
23 | | - |
24 | | -Removing this script is crucial because in the next step you add the jQuery script provided by Telerik. Having more than one script references causes errors. |
25 | | - |
26 | | -1. Add the jQuery script to the `<head>` tag. |
| 23 | +1. The ASP.NET Web Application template comes with a jQuery script reference at the end of `_Layout.cshtml` file. Locate the `@Scripts.Render("~/bundles/jquery")` line in the `<body>` of the document and move it to the `<head>`. Alterantively, use the jQuery script hosted on the jQuery CDN. |
27 | 24 |
|
28 | 25 | ```HTML |
29 | 26 | <head> |
30 | | -... |
31 | | -<link href="https://kendo.cdn.telerik.com/themes/{{ site.themesCdnVersion }}/bootstrap/bootstrap-main.css" rel="stylesheet" type="text/css" /> |
| 27 | +... |
| 28 | +<link href="https://kendo.cdn.telerik.com/themes/{{ site.themesCdnVersion }}/bootstrap/bootstrap-main.css" rel="stylesheet" type="text/css" /> |
32 | 29 |
|
33 | | -@* Add the jQuery script from the jQuery CDN: *@ |
34 | | -<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script> |
| 30 | +@* Add the jQuery script from the jQuery CDN: *@ |
| 31 | +<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> |
35 | 32 | </head> |
36 | 33 | ``` |
37 | | -1. Add the Kendo UI scripts. The Kendo UI script files required by UI for ASP.NET MVC must be loaded in the `<head>` tag *after* the jQuery script. |
| 34 | + |
| 35 | +1. Add the required Kendo UI script files in the `<head>` tag after the `jQuery` script reference: |
38 | 36 |
|
39 | 37 | ```HTML |
40 | 38 | <head> |
41 | | -... |
42 | | -<link href="https://kendo.cdn.telerik.com/themes/{{ site.themesCdnVersion }}/bootstrap/bootstrap-main.css" rel="stylesheet" type="text/css" /> |
43 | | -<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script> |
44 | | - |
45 | | -@* Add the Kendo UI scripts: *@ |
46 | | -<script src="https://unpkg.com/jszip/dist/jszip.min.js"></script> |
47 | | -<script src="https://kendo.cdn.telerik.com/{{ site.mvcCoreVersion }}/js/kendo.all.min.js"></script> |
48 | | -<script src="https://kendo.cdn.telerik.com/{{ site.mvcCoreVersion }}/js/kendo.aspnetmvc.min.js"></script> |
| 39 | +... |
| 40 | +<link href="https://kendo.cdn.telerik.com/themes/{{ site.themesCdnVersion }}/bootstrap/bootstrap-main.css" rel="stylesheet" type="text/css" /> |
| 41 | +<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> |
| 42 | + |
| 43 | +@* Add the Kendo UI scripts: *@ |
| 44 | +<script src="https://kendo.cdn.telerik.com/{{ site.mvcCoreVersion }}/js/kendo.all.min.js"></script> |
| 45 | +<script src="https://kendo.cdn.telerik.com/{{ site.mvcCoreVersion }}/js/kendo.aspnetmvc.min.js"></script> |
49 | 46 | </head> |
50 | 47 | ``` |
51 | | -1. Finally, add the `bootstrap.min.js` script available in Microsoft's ASP.NET Web Application template, and the `<head>` will look like this. |
| 48 | + |
| 49 | +> The installed {{ site.product }} NuGet package and the required [client-side assets]({% slug copyclientresources_aspnetmvc6_aspnetmvc %}) must have identical versions. |
| 50 | + |
| 51 | +1. Finally, add the `bootstrap.min.js` script available in ASP.NET Web Application template. The `<head>` tag must contain the following sylesheets and scripts: |
52 | 52 |
|
53 | 53 | ```HTML |
54 | | -<head> |
55 | | -<meta charset="utf-8" /> |
56 | | -<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
57 | | -<title>@ViewBag.Title - My Telerik MVC Application</title> |
58 | | -@Styles.Render("~/Content/css") |
59 | | -@Scripts.Render("~/bundles/modernizr") |
60 | | -<link href="https://kendo.cdn.telerik.com/themes/{{ site.themesCdnVersion }}/bootstrap/bootstrap-main.css" rel="stylesheet" type="text/css" /> |
61 | | -<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script> |
62 | | -<script src="https://unpkg.com/jszip/dist/jszip.min.js"></script> |
63 | | -<script src="https://kendo.cdn.telerik.com/{{ site.mvcCoreVersion }}/js/kendo.all.min.js"></script> |
64 | | -<script src="https://kendo.cdn.telerik.com/{{ site.mvcCoreVersion }}/js/kendo.aspnetmvc.min.js"></script> |
65 | | - |
66 | | -@* Add the bootstrap.min.js script: *@ |
67 | | -<script src="@Url.Content("~/Scripts/bootstrap.min.js")"></script> |
| 54 | + |
| 55 | +@Styles.Render("~/Content/css") |
| 56 | +@Scripts.Render("~/bundles/modernizr") |
| 57 | +<link href="https://kendo.cdn.telerik.com/themes/{{ site.themesCdnVersion }}/bootstrap/bootstrap-main.css" rel="stylesheet" type="text/css" /> |
| 58 | +<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> |
| 59 | +<script src="https://kendo.cdn.telerik.com/{{ site.mvcCoreVersion }}/js/kendo.all.min.js"></script> |
| 60 | +<script src="https://kendo.cdn.telerik.com/{{ site.mvcCoreVersion }}/js/kendo.aspnetmvc.min.js"></script> |
| 61 | +
|
| 62 | +@* Add the bootstrap.min.js script: *@ |
| 63 | +<script src="@Url.Content("~/Scripts/bootstrap.min.js")"></script> |
68 | 64 | </head> |
69 | 65 | ``` |
70 | 66 | >Always observe the following rules when adding client-side resources to your project: |
71 | | -> * Put the Kendo UI script files (`kendo.all.min.js` and `kendo.aspnetmvc.min.js`) after the `jquery.min.js` script. |
72 | | -> * A jQuery script must be loaded only once. It must be placed only in the `<head>` tag of the `_Layout.cshtml` file. Make sure there are no duplicate jQuery references elsewhere in the `_Layout` file. |
73 | | -> * The Kendo UI scripts, the Kendo UI CSS file must use a compatible version of the theme, and the `Kendo.Mvc.dll` referenced in the project must be the same version as the Kendo UI script files. |
| 67 | +> * Register the Kendo UI script files (`kendo.all.min.js` and `kendo.aspnetmvc.min.js`) after the `jquery.min.js` script. |
| 68 | +> * The jQuery script must be loaded only once. It must be placed only in the `<head>` tag of the `_Layout.cshtml` file. Ensure there are no duplicate jQuery references elsewhere in the `_Layout` file. |
| 69 | +> * The Telerik UI for ASP.NET MVC version and the version of the included Telerik UI theme must be mutually compatible. For more information, refer to the [compatibility table]({% slug sass_themes_compatibility_aspnetmvc6_aspnetmvc %}). |
| 70 | +> * The `Kendo.Mvc.dll` and the referenced Kendo UI scripts must have identical versions. |
74 | 71 |
|
75 | | -If you prefer to include the Kendo UI scripts and styles from a local source instead of CDNs, refer to the [Local Client-Side Resources]({% slug using_local_client_side_resources %}) article. |
| 72 | +If you prefer to include the client-side resources from a local source instead of CDNs, refer to the [Local Client-Side Resources]({% slug using_local_client_side_resources %}) article. |
76 | 73 |
|
77 | 74 | #end |
0 commit comments