How To Implement Footer Template In Kendo DropDownList

Introduction

In this blog, I’ll describe how to implement the footer template in the Kendo DropDownList, using ASP.NET MVC with an example that displays the total count of the list in footer template of the Kendo DropDownList.

Prerequisites

Basic knowledge of ASP.NET MVC and Kendo UI framework.

Create New MVC Project

Create a new empty ASP.NET MVC application as per the following figures. Open Visual Studio ->File ->New project ->ASP.NET Web Application.

MVC

Select MVC and click OK.

MVC

Please refer to my previous article, to check out how to configure Kendo UI in ASP.NET MVC application.

Creating the Model

Right click on the Models folder and go to Add->Class. In my case, I named it as EmployeeDetailList.cs.

Code in EmployeeDetailList.cs
  1. public class EmployeeDetailList {  
  2.     public EmployeeDetailList(int EmployeeID, string FirstName, string LastName) {  
  3.         this.EmployeeID = EmployeeID;  
  4.         this.FirstName = FirstName;  
  5.         this.LastName = LastName;  
  6.     }  
  7.     public int EmployeeID {  
  8.         get;  
  9.         set;  
  10.     }  
  11.     public string FirstName {  
  12.         get;  
  13.         set;  
  14.     }  
  15.     public string LastName {  
  16.         get;  
  17.         set;  
  18.     }  
  19. }  
Create a Controller

Create a new empty Controller. Right-click the Controllers folder and select Add –> New Empty Controller. In my case, I named it as EmployeeController.

Write the code, given below, in the Controller.
  1. public class EmployeeController: Controller {  
  2.     public ActionResult EmployeeList() {  
  3.         try {  
  4.             List < EmployeeDetailList > _emp = new List < EmployeeDetailList > ();  
  5.             _emp.Add(new EmployeeDetailList(1, "Bobb""Ross"));  
  6.             emp.Add(new EmployeeDetailList(2, "Pradeep""Raj"));  
  7.             _emp.Add(new EmployeeDetailList(3, "Arun""Kumar"));  
  8.             return Json(_emp.ToList(), JsonRequestBehavior.AllowGet);  
  9.         } catch (Exception ex) {  
  10.             return Json(ex.Message, JsonRequestBehavior.AllowGet);  
  11.         }  
  12.     }  
  13. }  
Creating a View

Right click on View-> Employee folder and add >> New Empty View. Write the code, given below, in the View-
  1. <div class="row">  
  2.     <div class="demo-section k-content">  
  3.         @(Html.Kendo().DropDownList() .Name("Empddl") .HtmlAttributes(new { style = "width:100%" }) .DataTextField("FirstName") .DataValueField("EmployeeID") .FooterTemplate("Total <strong>#: instance.dataSource.total() #</strong> items found") .DataSource(source => { source.Read(read => { read.Action("EmployeeList""Employee"); }); }) )  
  4.     </div>  
  5. </div>  
Footer Template

The footer template is the one of the new features of Kendo DropDownList from its latest 2016 R3 release. This footer template receives the DropDownList itself as a part of the data argument.

The footer template which is defined in the above View is used to display the total count of the employees in the DropDownList

Result

MVC

Conclusion

I hope you enjoyed this blog. Will share more details about other templates of the Kendo DropDownList in my future article. Your valuable feedback, questions, or comments about this article are always welcome.
Ebook Download
View all
Learn
View all