Kendo UI Grid With ASP.NET MVC

This article will show, how to work on Kendo UI Grid with ASP.NET MVC.

Create a new ASP.NET MVC project .

Configuring the Kendo UI in our application

Download Kendo UI for ASP.NET MVC here.

Install the TelerikUI for ASP.NET MVC Setup 2016, as shown in the figures, given below:

Install
 
The installation is straight forward. Just choose the required products. In my case, I have selected UI for ASP.NET MVC and click next.  

After completing the installation, copy the CSS and JS file from the installed location and paste it in your project. In my case, I have created the separate folder called Kendo in the Application and pasted the copied Kendo CSS and JS file inside the folder.

folder

folder

Open App_Start-> BundleConfig.cs to add the bundles for Telerik UI for ASP.NET MVC.

Add a script bundle for Telerik UI for ASP.NET MVC. 

  1. bundles.Add(new ScriptBundle("~/Kendo").Include("~/Kendo/js/kendo.all.min.js",  
  2.                "~/Kendo/js/kendo.aspnetmvc.min.js"));  

Adding style bundle is given below:

  1. bundles.Add(new StyleBundle("~/Kendo/styles").Include("~/Kendo/styles/kendo.common.min.css",  
  2.                 "~/Kendo/styles/kendo.default.min.css"));  

To allow the minified files in the debug mode, one can use:

  1. bundles.IgnoreList.Clear();  
Open the layout Application, by default, it is Views/Shared/_Layout.cshtml.
  1. @Scripts.Render("~/Kendo")  

Add the style bundle.

  1. @Styles.Render("~/Kendo/styles")  

Make sure that Jquery and the Kendo script bundle is moved to the head tag.

  1. @Scripts.Render("~/bundles/jquery")  
  2. @Scripts.Render("~/Kendo")  

Add the kendo.Mvc.dll reference

  1. Right-click the References  in Solution Explorer. Click Add Reference.
  2. Select the Browse tab of the Add Reference dialog. Navigate to the install location of Telerik UI for ASP.NET MVC.
  3. Navigate to wrappers/aspnetmvc/Binaries/MVC5. This directory contains ASP.NET MVC 5 version of Telerik UI for ASP.NET MVC.
  4. Select Kendo.Mvc.dll. Click OK.

    Kendo.Mvc.dll

Open the web.config file and add the Kendo UI namespace. 

  1. <add namespace="Kendo.Mvc.UI" />   
The setup is over. Now, let us see how to use Kendo Grid with HTML helpers. 

Create a new model class. In my case, I named it as Employee.cs.

  1. public class Employee  
  2.     {  
  3.           
  4.         public Employee(int EmployeeID, string FirstName, string LastName)  
  5.         {  
  6.             this.EmployeeID = EmployeeID;  
  7.             this.FirstName = FirstName;  
  8.             this.LastName = LastName;  
  9.         }  
  10.         public int EmployeeID { getset; }  
  11.         public string FirstName { getset; }  
  12.         public string LastName { getset; }  
  13.     }   

Add a controller, name it as Employee Controller and add the following Action Method in it.

  1. public ActionResult EmployeeList([DataSourceRequest]DataSourceRequest request)  
  2.         {  
  3.             try  
  4.             {  
  5.                 List<Employee> _emp = new List<Employee>();  
  6.                 _emp.Add(new Employee(1, "Bobb""Ross"));  
  7.                 _emp.Add(new Employee(2, "Pradeep""Raj"));  
  8.                 _emp.Add(new Employee(3, "Arun""Kumar"));  
  9.                 DataSourceResult result = _emp.ToDataSourceResult(request);  
  10.                 return Json(result,JsonRequestBehavior.AllowGet);  
  11.             }  
  12.         catch (Exception ex)  
  13.             {  
  14.                 return Json(ex.Message,JsonRequestBehavior.AllowGet);  
  15.   
  16.             }  
  17.         }  
Create a New empty index view with the default layout under employee folder and add the the following code in it: 
  1. <div class="container">  
  2.     <div class="row">  
  3.   
  4.         @(Html.Kendo().Grid<KendoStart.Models.Employee>()  
  5.     .Name("EmpGrid")  
  6.     .DataSource(dataSource => dataSource  
  7.         .Ajax()     
  8.           
  9.         .Read(read => read.Action("EmployeeList""Employee"))  
  10.         )  
  11.         )  
  12.     </div>  
  13. </div>  
Now, browse the Application.
 
Result 
 
Result
 
Yeah! the Kendo grid is successfully implemented in our ASP.NET MVC Application.
 
Source Code.

I hope you enjoyed this article. Your valuable feedback, questions or comments about this article are always welcome.

Up Next
    Ebook Download
    View all
    Learn
    View all