• .NET Developer Tools DevTools

    UI controls for ASP.NET AJAX, MVC, WPF,
    Silverlight, Windows 8 and Windows Phone

  • Hybrid Mobile Development Icenium

    Cross-platform Mobile Development Tool
    with cloud-based architecture

  • HTML5 / JavaScript Development Kendo UI

    Everything you need to build sites and
    mobile apps with JavaScript and HTML5

  • Testing Tools TestStudio

    One easy tool for Functional, Performance,
    Load and Mobile software testing

  • Web Presence Platform Sitefinity CMS

    Everything for your online business - content
    management, ecommerce, emarketing

  • Agile Project Management TeamPulse

    Simple and intuitive project management
    and collaboration software

Contact us

We are here for you.
  • usa+1‒888‒365‒2779
  • uk+44‒20‒7291‒0580
  • bg+359‒2‒8099850
  • de+49‒89‒2441642‒70
  • au+61‒2‒8090‒1465
  • emailsales@telerik.com
Your account Access to your products, updates and support
Telerik Product Families
  • Your Account
    Your Account
    Log in
  • ABOUT US

    About Telerik

    • Company
    • Press Center
    • Customers
    • Community
    • Careers
    • Contacts
Kendo UI - The way of HTML5
Products ▼
Kendo UI Web Kendo UI Mobile Kendo UI DataViz Server Side Wrappers
Demos Purchase Download
Blogs Documentation
Support ▼
Premium Forums StackOverflow Forums
Resources ▼

Featured Resource

Kendo UI Dojo


Blogs Code Library Demos Documentation FAQ Testing
Premium Forums Roadmap User Voice Videos Webinars More Resources
Contact Us Search
 

Blogs

HTML Helper Basics of Kendo UI for ASP.NET MVC Beta

Thursday, June 07, 2012 by Kendo UI Team Blog | Comments 12

HTML Helper Basics - Kendo UI for ASP.NET MVC Beta

Last week, we shipped the Beta release of Kendo UI for ASP.NET MVC. If you haven't already done so, I'd encourage you to check it out, especially if you're building websites with Kendo UI on ASP.NET MVC. In this blog post, we'll explore three basic concepts of using the HTML helpers of Kendo UI for ASP.NET MVC Beta; declarations, events, and configuration.

Download, Install, Integrate

To begin, the first thing we'll need to do is to download and install the MSI package for Kendo UI for ASP.NET MVC Beta (7.8 MB).

Download Kendo UI for ASP.NET MVC Beta

The installer will deploy a number of files to the destination folder, including the .NET assembly for Kendo UI for ASP.NET MVC, its associated JavaScript and stylesheet dependencies, documentation, and a set of examples highlighting the HTML helpers of Kendo UI for ASP.NET MVC Beta (more on this later). Important! The examples will NOT be installed unless ASP.NET MVC 3 is present.

Once the installer finishes, the next step is to integrate Kendo UI for ASP.NET MVC into your new/existing project(s). The steps to do this relatively simple. In fact, we've published a step-by-step guide to show you how to do this. It should only take a few minutes.

HTML Helpers

Now that everything is ready to go, the next step is to start using the HTML helpers that encapsulate the widgets for Kendo UI Web and Kendo UI DataViz.

HTML helpers are lightweight objects responsible for generating markup within a view. Kendo UI for ASP.NET Beta renders Web and DataViz widgets through as a set of custom HTML helpers defined in the Kendo.Mvc.UI namespace:

Web HTML Helpers

  • AutoComplete
  • Calendar
  • ComboBox
  • DatePicker
  • DateTimePicker
  • DropDownList
  • Grid
  • Menu
  • NumericTextBox
  • PanelBar
  • Slider
  • Splitter
  • TabStrip
  • TimePicker
  • TreeView
  • Window

DataViz HTML Helpers

  • Chart
  • LinearGauge
  • RadialGauge

Declarations

Let's start with a simple HTML helper that allows us to examine how they operate. In this case, let's assume the Calendar HTML helper:

Calendar HTML Helper (ASPX)

<%: Html.Kendo().Calendar()
	.Name("calendar")
%>

Calendar HTML Helper (Razor)

@(Html.Kendo().Calendar()
	.Name("calendar")
)

When the view is rendered, a Calendar widget is displayed in the browser:

Calendar Widget

Viewing the source, we see that the Calendar HTML helper is emiting the necessary markup and script to render the Calendar widget on the page:

Generated Output from Calendar HTML Helper

<div class="k-widget k-calendar" id="calendar"></div>
<script>
	jQuery(function(){jQuery("\#calendar").kendoCalendar({});});
</script>

Events

As you can see, the ID of the target div element (above) matches the Name of the Calendar HTML helper. This is intentional as well as mandatory; the ID provides a means of the auto-wiring of client-side events when configuring the Calendar HTML helper:

Calendar HTML Helper with Event (ASPX)

<%: Html.Kendo().Calendar()
	.Name("calendar")
	.Events(e => e.Change("change"))
%>

<script>
	function change() {
		// handle the date change event here...
	}
</script>

Calendar HTML Helper with Event (Razor)

@(Html.Kendo().Calendar()
	.Name("calendar")
	.Events(e => e.Change("change"))
)

<script>
	function change() {
		// handle the date change event here...
	}
</script>

In the code snippet(s) above, the Calendar HTML helper has been configured to have the resulting Calendar widget that's generated to invoke change when triggered by a user's interaction. Viewing the source, we see that the change event is appropriately configured:

Generated Output from Calendar HTML Helper with Event

<div class="k-widget k-calendar" id="calendar"></div>
<script>
	jQuery(function(){jQuery("\#calendar").kendoCalendar({change:change});});
</script>

<script>
	function change() {
		// handle the date change event here...
	}
</script>

As an aside, if you're targeting the Razor view engine, you can also utilize a templated Razor delegate to handle change events:

Calendar HTML Helper with Templated Razor Delegate

@(Html.Kendo().Calendar()
	.Name("calendar")
	.Events(e => e
		.Change(@<text>
			function() {
				/// handle the date change event here...
			}
		</text>)
	)
)

Configuration

Now, there's a good chance that we'll want to configure the Calendar HTML helper to modify its output and/or behavior. The APIs of the HTML helpers allow us to accomplish this task easily:

Calendar HTML Helper with Value Configuration (ASPX)

<%: Html.Kendo().Calendar()
	.Name("calendar")
	.Value(DateTime.Today)
%>

Calendar HTML Helper with Value Configuration (Razor)

@(Html.Kendo().Calendar()
	.Name("calendar")
	.Value(DateTime.Today)
)

When the view is rendered, the Calendar widget is displayed in the browser with its selected value set to today's date:

Calendar Widget with Value Configuration

It's worth noting how readable the code becomes through the fluent interface that's provided through method chaining. This style lends itself well to developers who have experience with Kendo UI already; it's similar to the one used to configure widgets for Kendo UI Web, Kendo UI DataViz, and Kendo UI Mobile. In the code snippet(s) above, the Value of the Calendar HTML helper is set to today's date, which generates the following output to the client:

Generated Output from Calendar HTML Helper

<div class="k-widget k-calendar" id="calendar"></div>
<script>
	jQuery(function(){jQuery("\#calendar").kendoCalendar({value:new Date(2012,5,7,0,0,0,0)});});
</script>

So, there you have it. In this blog post, we covered three basic concepts of using the HTML helpers of Kendo UI for ASP.NET MVC; declarations, events, and configuration. In future blog posts, we'll explore more advanced topics like databinding, migration, templates, and much more! In the meantime, please take the time to download the Beta and give it a try for yourself. Also, please send us your feedback! We really appreciate it.

About the Author
John Bristowe (@JohnBristowe) is a Developer Evangelist with Telerik and is based out of Melbourne, Australia. John enjoys all the meats of our technology stew, hacking on everything from angle brackets to .NET. John's passion lies in modern web standards like HTML5 and CSS3. His website is bristowe.com.

12 Comments

  1. 1 Hattan Shobokshi 08 Jun 2012
    Will the the RTM version include a visual studio project template or a quicker way to configure the helpers (something similar to the Telerik extenstions for ASP.NET MVC)? 
  2. 2 Stefan Rahnev 11 Jun 2012
    Yes, with the official release of Kendo UI for ASP.NET MVC we will include Visual Studio project templates for quick and easy configuration (identical to what we currently have with Telerik MVC Extensions).
  3. 3 Fab G. 28 Jun 2012
    Any plan to do anything similar for Ruby on Rails ?
  4. 4 Tony Galfano 03 Jul 2012
    How about php?
  5. 5 Avrohom Yisroel 10 Jul 2012
    Where is the download for this? The download page you linked has three options, the beta for Q2 2012 of KendoUI, a trial version of the full Kendo package and the KendoUI Web package.

    Your documentation http://www.kendoui.com/documentation/asp-net-mvc/introduction.aspx mentions downloading an msi file to install the ASP.NET MVC helpers for Kendo, but also doesn't say where to get it.

    Please can you provide a link, as I would like to use this. Thanks
  6. 6 Stefan Rahnev 10 Jul 2012
    Avrohom, here is the reply my colleague Sebastian provided in the support ticket you started with regards to this subject:

    You can download Kendo UI for ASP.NET MVC (part of the Kendo UI Q2'12 Beta) from this page's top section. The general instructions and folder structure of the zip download should be accurate.

    Note that the official release of this new product is slated for tomorrow. 

  7. 7 Brad D. 23 Jul 2012
    quick question: how do I extend a kendo ui widget wrapper for asp,net mvc, for example, the kendo ui combobox helper, i want to create a helper that outputs the kendo ui combobox and textarea side by side.
  8. 8 Riyasat 25 Jul 2012
    Hi,

    I had downloaded kendo ui open source and trying to follow the guide lines. But it seams that my downloaded file doesn't contain any wrapper class(es) for ASP.NET MVC. Can you please tell me how can or from where I can get this MVC wrapper class? Thanks

    Riy
  9. 9 Stefan Rahnev 25 Jul 2012
    Riyasat, the ASP.NET MVC wrappers are available in the Kendo UI Trial and Kendo UI Complete for ASP.NET MVC commercial distribution only. The open source version of Kendo UI Web (GPLv3) consist of the Kendo UI Web product solely.
  10. 10 Stefan Rahnev 20 Dec 2012
    The Kendo UI Trial package does not include an msi installer. It is available only with the Kendo UI Complete for ASP.NET MVC distribution. The reason for this is the trial package will incorporate more and more non-MVC products over time, and thus it can't feature a common msi installer.

    However, if you would like to utilize the MVC VS Extensions package which is integrated in the installer (project templates, upgrade/configuration wizards, etc.), you can download them directly from the Visual Studio Gallery:
    http://visualstudiogallery.msdn.microsoft.com/65b78c2c-951e-43a8-bae7-f9039f59fb9b
  11. 11 Andres 19 Dec 2012
    Hi Kendo team!

    I did not find any msi installer on provided page http://www.kendoui.com/download.aspx . I have not able to install Kendo UI due to I have not commercial license, please provide a valid download page to get MSI Installer.
    Thanks in advance
  12. 12 Peter 26 Apr 2013
    When specifying the name of the UI element, using your example:

    @(Html.Kendo().Calendar()
    .Name("calendar"))

    It is specified as a string not very compiler safe.
    Is there overloads so I could say:

    @(Html.Kendo().Calendar()
    .Name(m => m.SomePropOnMyViewsModel)

Comment

  1. Click to add

  2. Click to add

  3. Click to add

  4.    
     
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
     
      
       
Blogs feed
Categories

  • Tutorials (26)
  • Release (33)
  • Browsers (7)
  • Extensions (3)
  • Tip of the Week (10)
  • Videos (5)
  • Concepts and Theory (13)
  • Misc. (25)
  • Framework Constructs (6)
  • Mobile (6)
  • UI Widgets (5)
  • Blogs (1)
Archive
  • 2013 May (7)
  • 2013 April (10)
  • 2013 March (9)
  • 2013 February (12)
  • 2013 January (10)
  • 2012 December (9)
  • 2012 November (11)
  • 2012 October (6)
  • 2012 September (7)
  • 2012 August (8)
  • 2012 July (10)
  • 2012 June (8)
  • 2012 May (10)
  • 2012 April (7)
  • 2012 March (13)
  • 2012 February (10)
  • 2012 January (6)
  • 2011 December (10)
  • 2011 November (4)
  • 2011 October (6)
  • 2011 September (5)
  • 2011 August (9)
Home Web Mobile DataViz Server Wrappers Whitepapers Surveys Chrome Icenium Contact Us

Kendo UI framework is developed by Telerik - a leading provider of UI components for web, desktop and mobile applications. Trusted by over 100,000 customers worldwide for our devotion to quality and industry-best technical support, Telerik helps professionals maximize their productivity and "deliver more than expected" every day.

kendoui - powered by html5, css3 & jquery
get social
  • Twitter
  • Facebook
  • Google plus
  • RSS
Privacy Policy | Branding Guidelines
Powered by Sitefinity CMS

Copyright © 2011 - 2013 Telerik Inc. All rights reserved.