Create a new ASP.NET MVC 5 Application
To create a new ASP.NET MVC 5 Application follow these steps.
- Open Visual Studio 2013.
- Press CTRL+SHIFT+N to create a new project.
- Select the Visual C# node and then Web to show all available web project templates for C#.
- Select ASP.NET Web Application and click OK. This will start the New ASP.NET Project wizard.
- Select MVC from the available templates and click OK.
- Press CTRL+F5 to build and run the application.
Include the JavaScript and CSS files
Kendo UI requires certain JavaScript and CSS files to be included in the page. There are two options - either to include a local copy of those filesor to use Kendo UI CDN (Content Delivery Network).
Using local JavaScript and CSS
To copy the Kendo UI JavaScript and CSS files in the Visual Studio Solution of the application follow these steps.
1. Copy the js directory from the install location and paste it in the Script folder of the application.
2. Copy the styles directory from the install location and paste it in the Content folder of the application.
3. Rename the Scripts/js directory to Scripts/kendo.
4. Rename Content/styles to Content/kendo.
After the Kendo UI JavaScript and CSS files are added in the application you can include them.
- Open App_Start/BundleConfig.cs to add bundles for Kendo UI.
- Add a script bundle for Kendo UI.
bundles.Add(new ScriptBundle("~/bundles/kendo").Include(
"~/Scripts/kendo/kendo.all.min.js",
// "~/Scripts/kendo/kendo.timezones.min.js", // uncomment if using the Scheduler
"~/Scripts/kendo/kendo.aspnetmvc.min.js"));
- Add a style bundle for Kendo UI.
bundles.Add(new StyleBundle("~/Content/kendo/css").Include(
"~/Content/kendo/kendo.common-bootstrap.min.css",
"~/Content/kendo/kendo.bootstrap.min.css"));
- Tell ASP.NET bundles to allow minified files in debug mode.
bundles.IgnoreList.Clear();
- Open the layout of the application. By default it is Views/Shared/_Layout.cshtml (or Site.master if using ASPX).
- Render the Kendo UI style bundle.
- Move the jQuery bundle to the head tag of the page. It is at the end of the page by default.
- Render the Kendo UI script bundle after jQuery.
Using Kendo UI CDN
To include the Kendo UI JavaScript and CSS files from CDN follow these steps. Important! Don't forget to replace "kendo ui version" from the code snippets below with the current version of Kendo UI e.g. "2013.2.918".
- Open the layout of the application. By default it is Views/Shared/_Layout.cshtml (or Site.master if using ASPX).
- Include kendo.common-bootstrap.min.css and kendo.bootstrap.min.css. Add a link tag within the head tag of the layout.
<link rel="stylesheet" href="http://cdn.kendostatic.com/<kendo ui version>/styles/kendo.common-bootstrap.min.css" />
<link rel="stylesheet" href="http://cdn.kendostatic.com/<kendo ui version>/styles/kendo.bootstrap.min.css" />
- Move the jQuery bundle to the head tag of the page. It is at the end of the page by default.
- Include kendo.all.min.js and kendo.aspnetmvc.min.js after jQuery.
<script src="http://cdn.kendostatic.com/<kendo ui version>/js/kendo.all.min.js"></script>
<script src="http://cdn.kendostatic.com/<kendo ui version>/js/kendo.aspnetmvc.min.js"></script>
- If using Kendo UI Scheduler include kendo.timezones.min.js after kendo.all.min.js
<script src="http://cdn.kendostatic.com/<kendo ui version>/js/kendo.all.min.js"></script>
<script src="http://cdn.kendostatic.com/<kendo ui version>/js/kendo.timezones.min.js"></script>
<script src="http://cdn.kendostatic.com/<kendo ui version>/js/kendo.aspnetmvc.min.js"></script>
The next step is to add a reference to Kendo.Mvc.dll which is the assembly containing the Kendo UI server-side wrappers.
- Right-click the References node in Solution Explorer and click Add Reference.
- Select the Browse tab of the Add Reference dialog and navigate to the install location of Telerik UI for ASP.NET MVC.
- Navigate to wrappers/aspnetmvc/Binaries/MVC5. This directory contains the ASP.NET MVC 5 version of Telerik UI for ASP.NET MVC.
- Select Kendo.Mvc.dll and click OK.
The next step is to let ASP.NET MVC know of the Kendo.Mvc.UI namespace where the server-side wrappers are. To do this update the web.config file of the web application.
- Open Views/Web.config (or root Web.config if using ASPX).
- Locate the namespaces tag.
- Append an add tag to the namespaces tag.
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Kendo.Mvc.UI" />
</namespaces>
Finally lets use a Kendo UI widget.
- Open the Views/Home/Index.cshtml view (or Index.aspx if using ASPX).
- Add a Kendo UI DatePicker widget.
- Press CTRL+F5 to build and run the application.