# Tuesday, 19 June 2012

Back in April I started a series of posts related to using Kendo UI in ASP.NET MVC.  Last month the Kendo team released the first beta of Kendo UI for ASP.NET MVC.  So, long story short the blog posts on Kendo UI will continue but from this point forward they will move from implementing Kendo UI proper in ASP.NET MVC to using Kendo UI for ASP.NET MVC.

Kendo UI for ASP.NET MVC includes the complete Kendo UI suite (Web, Mobile, DataViz) plus a set .NET wrappers to be used with ASP.NET MVC that leverage exciting features of MVC such as data annotations, editor/display templates and validation.  Those of you still using the WebForms view engine are safe,  the wrappers work in both the Razor view engine and the WebForms view engine.

To get started download the Kendo UI for ASP.NET MVC bits and install them.  The bits include, what I would call, the Kendo UI core features plus all the ASP.NET MVC specific features so there is no need install both Kendo UI and Kendo UI for ASP.NET MVC.  If you already have Kendo UI core installed, don’t worry, the installer will adjust accordingly.

Once installed pull up the install location, for me it is “C:\Program Files (x86)\Telerik\Kendo UI for ASP.NET MVC Q2 2012 BETA”, and play around with the example projects by running “\Examples\StartExamples.exe”.

Now…let’s get it up and running in an ASP.NET MVC project.

NOTE: The Kendo UI for ASP.NET MVC documentation states that both MVC 3 and MVC 4 are supported even though the actual Kendo.MVC.dll resides in the “Mvc3” directory.

  1. Create a new ASP.NET MVC 3 or 4 project
  2. Add a reference to: [Kendo UI Directory]\Binaries\Mvc3\Kendo.Mvc.dll
  3. Copy the contents of [Kendo UI Directory]\Scripts to the Scripts folder of your MVC project
  4. Copy the contents of [Kendo UI Directory]\Content to the Content folder of your MVC project
  5. Reference the Kendo UI scripts and and CSS files in your layout page.
    *Note: If your using ASP.NET MVC 4 I suggest creating a bundler package

    <link rel="stylesheet" href="@Url.Content("~/Content/kendo.common.min.css")">
    <link rel="stylesheet" href="@Url.Content("~/Content/kendo.default.min.css")">
    <script src="@Url.Content("~/Scripts/jquery.min.js")"></script>
    <script src="@Url.Content("~/Scripts/kendo.web.min.js")"></script>
    <script src="@Url.Content("~/Scripts/kendo.aspnetmvc.min.js")"></script>
  6. Add a reference to the Kendu.Mvc.UI namespace to the <namespaces> section of the web.config to allow your views to know about the Kendo HTML Helper extensions.
    <add namespace="Kendo.Mvc.UI"/>
  7. Let’s test it out.  Open up Index.cshtml and create a Kendo UI control using the new HTML Helpers.
    @(Html.Kendo().DatePicker().Name("MyTestDatePicker"))

 

image

As with the previous parts of the series the code is available on GitHub.

posted on Tuesday, 19 June 2012 11:15:53 (Central Daylight Time, UTC-05:00)  #    Comments [6]
# Monday, 21 May 2012

Continuing from my previous post Getting Started with Kendo UI in ASP.NET MVC, let’s dive in to Kendo UI’s AutoComplete control.  The Kendo UI AutoComplete control is a text box that has an associated list of items that when text is entered into it a suggestion list is displayed allowing the user to select an item.

To get started I created a blank MVC project and wired up Kendo UI per the instructions in my Getting Started post.

Next I created a server side model: Manufacturer.cs

   1: namespace Part2_AutoComplete.Web.Models {
   2:  
   3:     public class Manufacturer {
   4:         public int Id { get; set; }
   5:         public string Name { get; set; }
   6:     }
   7: }

As you can see the view the model is a very simple class that contains only an Id and a Name field.

After that I created my view: Index.cshtml

   1: @model Part2_AutoComplete.Web.Models.Manufacturer
   2: @{
   3:     ViewBag.Title = "Getting Started With KendoUI - Part 2: Auto Complete";
   4: }
   5:  
   6: <script type="text/javascript">
   7:     $(document).ready(function () {
   8:         $("#Name").kendoAutoComplete({
   9:             minLength: 1,
  10:             dataTextField: "Name",
  11:             suggest: true,
  12:             filter: "startswith",
  13:             dataSource: { serverFiltering: true,  transport: {read: {url: "/Home/GetManufacturers/",dataType: "json", type: "POST"}}}
  14:         });
  15:     });
  16: </script>
  17:  
  18: <h2>@ViewBag.Title</h2>
  19:  
  20: @using(Html.BeginForm()) {
  21:     <div id="root">
  22:         <div id="manufacturers">
  23:             @Html.HiddenFor(x => x.Id)
  24:             <label for="input" class="info">Choose a car manufacturer:</label>
  25:             @Html.TextBoxFor(m => m.Name)
  26:             <div class="hint">Start typing the name of a car manufacturer <br/>(Aston Martin, Bugatti, Ferrari, Lamborghini, Porsche) </div>
  27:         </div>
  28:     </div>
  29:     <input type="submit" value="Send Back To Server"/>
  30:     <h3>@ViewBag.Message</h3>
  31: }

Assuming you are an ASP.NET MVC developer that uses Razor, the majority of the view code above should look familiar.  The lines to focus on are 8 – 14, which are the actual implementation of the Kendo UI AutoComplete.  Let’s break down the configuration options that I am passing to kendoAutoComplete:

  • minLength:  number of characters to be entered before filtering the data
  • dataTextField: field in the data source that represents the content of the list items
  • suggest: controls if the rest of the text for the item that matches is automatically displayed in the text box
  • filter: type of filtering to apply the data (“startswith”, “contains”, etc.)
  • dataSource: data that the control is bound to, can either be a JavaScript object or a Kendo UI DataSource
    • As you can see I am using a Kendo UI DataSource that makes an AJAX call to the GetManufactures method on the Home controller.

That is the complete client side implementation of the Kendo UI AutoComplete.  More details on what configuration is available for the AutoComplete can be found here.

Lastly we can code our controller: HomeController.cs

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Linq;
   4: using System.Web.Mvc;
   5: using Part2_AutoComplete.Web.Models;
   6:  
   7: namespace Part2_AutoComplete.Web.Controllers {
   8:  
   9:     public class HomeController : Controller {
  10:  
  11:         [HttpGet]
  12:         public ActionResult Index() {
  13:             return View(new Manufacturer{Id = 1, Name = "Aston Martin"});
  14:         }
  15:  
  16:         [HttpPost]
  17:         public ActionResult Index(Manufacturer manufacturer) {
  18:             ViewBag.Message = string.Format("You selected \"{0}\" and sent it to the server!", manufacturer.Name);
  19:             return View();
  20:         }
  21:  
  22:         [HttpPost]
  23:         public JsonResult GetManufacturers() {
  24:             string searchValue = Request.Params["filter[filters][0][value]"];
  25:             IList<Manufacturer> manufacturers = BuildManufacturersList()
  26:                 .Where(x => x.Name.StartsWith(searchValue, StringComparison.InvariantCultureIgnoreCase)).ToList();
  27:             return Json(manufacturers);
  28:         }
  29:  
  30:         private IList<Manufacturer> BuildManufacturersList() {
  31:             IList<Manufacturer> manufacturers = new List<Manufacturer>();
  32:             manufacturers.Add(new Manufacturer {Id = 1, Name = "Aston Martin"});
  33:             manufacturers.Add(new Manufacturer {Id = 2, Name = "Audi"});
  34:             manufacturers.Add(new Manufacturer {Id = 3, Name = "Buggati"});
  35:             manufacturers.Add(new Manufacturer {Id = 4, Name = "BMW"});
  36:             manufacturers.Add(new Manufacturer {Id = 5, Name = "Chevrolet"});
  37:             manufacturers.Add(new Manufacturer {Id = 6, Name = "Ferrari"});
  38:             manufacturers.Add(new Manufacturer {Id = 7, Name = "Ford"});
  39:             manufacturers.Add(new Manufacturer {Id = 8, Name = "Lamborghini"});
  40:             manufacturers.Add(new Manufacturer {Id = 9, Name = "Mazda"});
  41:             manufacturers.Add(new Manufacturer {Id = 10, Name = "McLaren"});
  42:             manufacturers.Add(new Manufacturer {Id = 11, Name = "Mercedes Benz"});
  43:             manufacturers.Add(new Manufacturer {Id = 12, Name = "Porsche"});
  44:             return manufacturers;
  45:         } 
  46:     }
  47: }

The controller code is very straightforward.  Notice the GetManufacturers method that starts on line 30, it handles the AJAX request from the client and returns the JSON that is used to build the Kendo UI DataSource that drives that Kendo UI AutoComplete.

The code is available on GitHub.

If you haven’t checked out the recently released GitHub for Windows client, I highly suggest you check it out!

posted on Monday, 21 May 2012 15:18:54 (Central Daylight Time, UTC-05:00)  #    Comments [11]
# Monday, 14 May 2012

Once again I am plugging That Conference!  Why?  Because it is going to kick ass and you will not want to miss it!

In a previous post I highlighted some of the nationally recognized top-notch speakers that will be Counselors at the event.  What I didn’t mention is that I have been given the honor of presenting not one but two sessions at That Conference.  Below are the two sessions I will be doing.

Going Native with KendoUI Mobile
The number of people using their smartphones or tablets to access the web has grown to the point where having a presence on mobile devices has become a must for anyone with a website. But to be truly successful your mobile presence has to differentiate itself from the mobile web entirely and straddle that line between web and native application. In the past this meant having specific styles and often views for each specific mobile platform you wanted to target, but this is no longer necessary thanks to Kendo UI Mobile.

In this talk Keith will demonstrate how using HTML5 and Kendo UI Mobile you can write one application with a single set of styles and views that looks truly native on iOS, Android, and Blackberry. Keith will walk through creating a mobile application from start to finish including how to use PhoneGap to package and deploy your website to the major mobile application stores.

 

HTML5 – It’s Not Just for Hipsters
HTML5 is the current “Big Thing” in web technologies. HTML5 has already been crowned the “Write Once Run Everywhere” toolset, even running on the desktop. But we .NET guys seem to once again, be left behind. The lack of tooling in Visual Studio along with the fact that most .NET web developers do not consider themselves HTML developers is really causing .NET developers to already be behind the 8 ball when it comes to HTML5 development.

In this talk Keith will cover the features of HTML5 that all .NET developers should know about and be taking advantage of. He will also cover, how contrary to popular belief the tooling is there and you can start coding HTML5 in Visual Studio now. Keith will also demonstrate that HTML5 development does not require a completely new toolset, you can leverage your current skills including all your favorite .NET server technologies when doing HTML5 development.

I highly suggest you take a look at the awesome array of sessions that will be presented at That Conference in each of the 4 tracks:

On top of the Give Camp leading in to the event there are a number of other awesome events being planned.  Unfortunately these events are still in the planning phase so I can’t go in to detail but I can stress Do Not Miss That Conference!

posted on Monday, 14 May 2012 07:41:41 (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Tuesday, 08 May 2012

That Conference announced the initial session line up earlier this week and in a word AWESOME! 

The official speaker line up will be announced shortly and includes the following;

For a line up like that you would expect to have to travel to one of the coast’s and spend a fortune but that is not the case.  That Conference was formed under the premise of bringing a top quality conference (speakers, content, etc.) to the upper Midwest that everyone can afford to attend.  If you are in the Midwest this is an excellent opportunity that you should not miss!  Registration opens May 16th at 8:13am CST.  You will want to get in early as this is going to be one hot ticket.

posted on Tuesday, 08 May 2012 07:47:42 (Central Daylight Time, UTC-05:00)  #    Comments [3]
# Monday, 30 April 2012

I have recently started diving in to Kendo UI and have decided to document that dive and blog about it.  So this is the first post in a series dedicated to using Kendo UI in ASP.NET MVC.

Kendo UI is a JavaScript toolset developed by Telerik that leverages jQuery, HTML5, CSS3, and JavaScript to provide rich UI widgets and an MVVM framework that is ‘scary fast’.  The thing that really drew me to Kendo UI in the first place is there native skinning on mobile devices.  Unlike vanilla jQuery Mobile that renders the same iOS-esque view on all mobile devices Kendo UI Mobile applies specific native-looking styles for iOS, Android, and Blackberry.  Over the series of posts I have planned we will cover exactly what Kendo UI brings to the table for both the ‘desktop’ web and the mobile web, but today I will cover getting Kendo UI installed and configured in an ASP.NET MVC application.

Before we dive in to getting the bits I want to prepare you…Kendo UI is not free.  I know, I was surprised by this as well and it actually delayed my dive in to it for a bit.  In all honesty I am still not 100% sure how I feel about it not being free.  What I do know is that as a long time user of Telerik products they produce damn good tooling and there support system is second to none.  If you want to just play around with Kendo UI there is a 60-day free trial available.

Update: I received a comment from a member of the KendoUI team, thanks John, and my statement above needs some clarification.  Kendo UI is dual licensed (GPLv3 and commercial), so although it is not free for commercial use they do support open source development.  You can can get the official terms here: http://www.kendoui.com/get-kendo-ui.aspx

Note: To prepare for experimenting with KendoUI I created an empty MVC 4 project, that of course is not empty, and removed all scirpt and css files (other than Site.css).  I then removed all script and css registrations in _Layout.cshtml.  I did this because I wanted to deal strictly with KendoUI without all the other *noise* of the other script references.

You can download the KendoUI bits here: http://www.kendoui.com/get-kendo-ui.aspx

Once downloaded and unzipped copy the contents of the ‘js’ directory to the ‘Scripts’ directory of your ASP.NET MVC application and the contents of the ‘styles’ directory to the ‘Content’ directory.

Next you need to register the scripts and CSS files that Kendo UI needs in the _Layout.cshtml.

_Layout.cshtml
  1. DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8" />
  5.         <meta name="viewport" content="width=device-width" />
  6.         <title>@ViewBag.Titletitle>
  7.         <script src="~/Scripts/jquery.min.js">script>
  8.         <script src="~/Scripts/kendo.all.min.js">script>
  9.         <link href="~/Content/kendo.common.min.css" rel="stylesheet" type="text/css"/>
  10.         <link href="~/Content/kendo.default.min.css" rel="stylesheet" type="text/css"/>
  11.     head>
  12.     <body>
  13.         @RenderBody()
  14.     body>
  15. html>

That’s it.  Kendo UI is now wired up.  Pretty much the same process as wiring up jQuery.  So now we can do a quick implementation to prove it.

If you followed my lead and created an empty project you you will need to create a controller and a view at this point.

The actual implementation of KendoUI is almost identical to that of jQuery which makes the ramp up time a lot less if you are familiar with jQuery.

Index.cshtml
  1. @{
  2.     ViewBag.Title = "Getting Started With KendoUI - Installation and Configuration";
  3. }
  4.  
  5. <script type="text/javascript">
  6.     $(document).ready(function(){
  7.         $("#datePicker").kendoDatePicker();
  8.     });
  9. script>
  10.  
  11. <h2>@ViewBag.Titleh2>
  12.  
  13. <input id="datePicker" />

As you can see on line 13 I have an input tag with and id of datepicker and then starting on line 5 I have my document ready function that selects the control with id of datepicker and calls the ‘kendoDatePicker’ function it.  The result is below.

 

KendoUI Calendar

In the next installment we will dig deeper into the different controls available in Kendo UI.

If you want to follow along with the source code it is available on GitHub.

posted on Monday, 30 April 2012 14:01:26 (Central Daylight Time, UTC-05:00)  #    Comments [14]