Server Binding
By default, the Telerik UI Grid for ASP.NET MVC sends HTTP GET requests to the server for paging, sorting, and filtering operations.
Supported Client-Side Events
The Grid supports the following client-side events when it is in server binding mode:
ChangeColumnHideColumnMenuInitColumnReorderColumnResizeColumnShowDetailCollapseDetailExpandExcelExportFilterMenuInitPdfExportGroupExpand—The group object that is associated with group row will be empty in server binding scenario.GroupCollapse—The group object that is associated with group row will be empty in server binding scenario.
- Client-side events related to data binding and CRUD operations are not raised when the Grid is configured for server binding.
- Locked columns are not supported. To use locked columns, use Ajax binding.
- Showing or hiding columns and reordering with
GroupHeaderColumnTemplatein server-binding scenarios is not supported. In server-binding scenarios, the Kendo UI for jQuery DataSource instance does not include group and aggregate information, so group-row templates cannot be compiled on the client.- Row spanning is not supported. To use row and column spanning, use Ajax binding and review Row and Column Spanning.
Getting Started
To bind the Grid to data, set its data source and render the view by using any of the following approaches:
- Bind to the view model
- Bind to items from
ViewDataorViewBag - Use the
BindTomethod - Pass additional data to an action method
Binding to the View Model
The example below demonstrates how to bind the Grid to a model.
public ActionResult Index()
{
var northwind = new NorthwindEntities();
var products = northwind.Products;
return View(products);
}Using the ViewData or ViewBag Items Binding
The following example demonstrates how to apply data binding with ViewData or ViewBag.
public ActionResult Index()
{
var products = new NorthwindDataContext().Products;
ViewData["products"] = products;
return View();
}Applying the BindTo Method
The following example demonstrates how to bind the Grid to data by using the BindTo method.
public ActionResult Index()
{
var products = new NorthwindDataContext().Products;
ViewBag.Products = products;
return View();
}The Grid makes HTTP GET requests to the action method that initially renders the view. The Grid page, sort, filter, and group information is passed as query string parameters.
For example, a server-bound Grid URL can look like http://localhost:4939/?Grid-sort=ProductName-asc&Grid-page=2. The Grid Name is used as a query-string prefix so multiple server-bound Grid instances can coexist in the same view. You can disable the prefix through the PrefixUrlParameters method.
<%: Html.Kendo().Grid(Model)
.Name("Grid")
.PrefixUrlParameters(false)
%>
Passing Additional Data to Action Methods
The action method that renders the view containing the Grid may need additional data.
public ActionResult Index(string firstName, string lastName)
{
var products = new NorthwindDataContext().Products;
return View(products);
}Setting Up the Sample Project
-
Create a new ASP.NET MVC 5 application. If you have installed the Telerik UI for ASP.NET MVC Visual Studio Extensions, create a Telerik UI for ASP.NET MVC application. Name the application
KendoGridServerBinding. If you decided not to use the Telerik UI for ASP.NET MVC Visual Studio Extensions, follow the steps from the introductory article to add Telerik UI for ASP.NET MVC to the application. -
Add a new
Entity Framework Data Model. Right-click the~/Modelsfolder in the solution explorer and pick Add new item. Choose Data > ADO.NET Entity Data Model in the Add New Item dialog. Name the modelNorthwind.edmxand click Next. This starts the Entity Data Model Wizard.
-
Pick the EF Designer from database option and click Next. Configure a connection to the Northwind database. Click Next.

-
Choose the Products table from the
Which database objects do you want to include in your model?. Leave all other options as they are set by default. Click Finish.
-
Open HomeController.cs and modify the
Indexaction method.C#public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; var northwind = new NorthwindEntities(); // Get the Products entities and add them to the ViewBag. ViewBag.Products = northwind.Products; return View(); } -
Modify the
Createmethod as demonstrated in the following example.C#[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Product product) { if (ModelState.IsValid) { productService.Create(product); RouteValueDictionary routeValues = this.GridRouteValues(); return RedirectToAction("Index", routeValues); } return View("Index", productService.GetAll()); } -
Modify the
Updatemethod as demonstrated in the following example.C#[AcceptVerbs(HttpVerbs.Post)] public ActionResult Update(Product product) { if (ModelState.IsValid) { productService.Update(product); RouteValueDictionary routeValues = this.GridRouteValues(); return RedirectToAction("Index", routeValues); } return View("Index", productService.GetAll()); } -
Modify the
Destroymethod as demonstrated in the following example.C#[AcceptVerbs(HttpVerbs.Post)] public ActionResult Destroy(int productID) { Product product = productService.GetAll().FirstOrDefault(p => p.ProductID == productID); RouteValueDictionary routeValues; if (product == null) { routeValues = this.GridRouteValues(); return RedirectToAction("Index", routeValues); } productService.Destroy(product); routeValues = this.GridRouteValues(); return RedirectToAction("Index", routeValues); } -
Add a Kendo UI Grid to the
Indexview.Razor@(Html.Kendo().Grid((IEnumerable<KendoGridServerBinding.Models.Product>)ViewBag.Products) //Bind the grid to ViewBag.Products .Name("grid") .Columns(columns => { columns.Bound(product => product.ProductID); columns.Bound(product => product.ProductName); columns.Bound(product => product.UnitsInStock); columns.Bound(product => product.Discontinued); columns.Command(commands => { commands.Edit(); // The "edit" command will edit and update data items. commands.Destroy(); // The "destroy" command removes data items. }).Title("Commands").Width(300); }) .ToolBar(commands => commands.Create()) .Pageable() //Enable the paging. .Sortable() //Enable the sorting. .DataSource(dataSource => dataSource .Server() // Specify that the ProductID property is the unique identifier of the model. .Model(model => model.Id(p => p.ProductID)) .Create(create => create.Action("Create", "Home")) .Update(update => update.Action("Update", "Home")) .Destroy(destroy => destroy.Action("Destroy", "Home")) ) ) -
Build and run the application.
