How can I use Kendo UI with Razor?

14,871

In order to use additional helpers, you need to register them with Razor view engine. This is done in web.config file, or using @using statement on top of .cshtml file.

Here's an example from my web.config

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="Kendo.Mvc.UI"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>

As far as licensing goes, this is not a freeware software. You can see licensing terms and prices on their website. As per their license, each developer which uses Telerik controls needs to have a license. License is not company wide, or project wide.

You don't need to install vsix, but it could make your life easier by automatically adding references to required assemblies, and adding required entries to web.config files.

Share:
14,871
Lajos Arpad
Author by

Lajos Arpad

I was very much interested how computer games work as a kid. I have seen that game graphics are displayed and the logic of the game works well, yet, I knew that this was physically manifested as cables. I decided to become a programmer, since I wanted to know what was behind the wonder that based on cables and electricity a virtual reality is created. Also, I realized that I should not choose another profession, since my handwriting is unreadable. As a kid, nobody took me seriously and when I had a question about programming, I had to go to the library to find the right chapter in the right book. Today, this has become simpler and I am happy to contribute to helping other fellow programmers. In the spirit of Knuth, I consider programming an art and I improve my source-code until I no longer see the difference between profession and art.

Updated on June 05, 2022

Comments

  • Lajos Arpad
    Lajos Arpad almost 2 years

    I have downloaded and used Kendo UI with Kendo UI grids, but my source code was very complicated, for several reasons:

    1. I've hacked the sort to enable case insensitive sorting.

    2. I've observed UI bugs when displaying filter menu, page size selector, filter function menu and DatePicker in the filter menu; I've solved these problems with ugly hacks.

    3. On client-side I've refreshed the grid when needed using parameterized posts.

    4. On server-side I have created a function which handled the sort, filter, page size and paging state of the grid dynamically.

    However, my client told me that we need a "simple" solution, a grid page should be completed in an hour. I think this is unrealistic with my current approach unless I implement a generalized class to handle the grids. This would be possible using Linq, to handle the tables, fields, filters, sorts, paging and page size. I know this for sure, as my code is not so far from being a general-purpose grid supporter on server-side and a Kendo UI grid factory on client-side. However, my client clearly stated that we don't need to implement this class and prototype, because we should be able to configure Kendo UI simply. He told me (the previously unspecified detail) that we are allowed to return all the rows from a table and filter/sort that on client-side, so points 3 and 4 would become unneeded.

    I have been looking at the example here. I would like to have something similar as the example in cshtml. However, in my downloaded Telerik Kendo UI I don't have any server-side content, so the IDE is showing that Html.Kendo().Grid(Model) is incorrect. The error is as follows:

    Error 10 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'Kendo' and no extension method 'Kendo' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

    I am using ASP.NET MVC3 with Linq.

    How can I use Telerik Kendo UI with ASP.NET Razor in the style described in the cshtml file in the link? Is this gratis? If no, how much is the cost? Should I install KendoUI.Mvc.VSPackage.vsix?

    • Pablo Claus
      Pablo Claus over 11 years
      No, Kendo for MVC is not "gratis". What version do you have?
  • Lajos Arpad
    Lajos Arpad over 11 years
    Thank you for your answer. Do I need to download something?
  • Lajos Arpad
    Lajos Arpad over 11 years
    This is the error I get: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\2eb65780\a625994f\App_Web_error500.cshtml.6259942‌​8.kfutdc2x.0.cs(27): error CS0246: The type or namespace name 'Kendo' could not be found (are you missing a using directive or an assembly reference?)
  • Nikola Radosavljević
    Nikola Radosavljević over 11 years
    You need to have Kendo assemblies and scripts. If you don't have them (if you started from new project and didn't install Kendo), then you need to download Kendo and install it.
  • Nikola Radosavljević
    Nikola Radosavljević over 11 years
    In that case you don't have Kendo assemblies. Download and install them. There is trial version available, or if you're developing software with GPLv3 license (probably not), you can get a free license.
  • Lajos Arpad
    Lajos Arpad over 11 years
    Thank you for this nice answer.