New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Bind Grid to Collections of Dynamic Objects
Environment
Product | Telerik UI for ASP.NET MVC Grid |
Product version | 2025.1.227 |
Description
How can I bind the Grid to a collection of dynamic objects?
Solution
You can achieve this requirement using the following implementation:
-
Define the View's model as
IEnumerable<dynamic>
and bind the Grid to this model. Also, configure the Grid for Ajax data bidning.Razor@model IEnumerable<dynamic> @(Html.Kendo().Grid(Model) .Name("Grid") .DataSource(ds => ds .Ajax() .Model(m => { m.Id("ProductID"); m.Field("ProductID", typeof(int)); m.Field("ProductName", typeof(string)); m.Field("UnitPrice", typeof(decimal)); m.Field("QuantityPerUnit", typeof(string)); }) .Read(r => r.Action("Read", "Home")) .Update(u => u.Action("Update", "Home")) .Destroy(u => u.Action("Destroy", "Home")) .Create(u => u.Action("Create", "Home")) ) ... // Additional configuration )
-
Set up the Read Action method of the Grid to retrieve the data:
C#public ActionResult Read([DataSourceRequest] DataSourceRequest request) { return GetView(request); } private IEnumerable<dynamic> GetData() { var db = new GridBindingDynamicCollectionEntities(); return db.Products; } private JsonResult GetView(DataSourceRequest request) { return Json(GetData().ToDataSourceResult(request)); }
To review the complete example, refer to the ASP.NET MVC project on how to bind the Telerik UI for ASP.NET MVC Grid to a collection of dynamic objects.
More ASP.NET MVC Grid Resources
- ASP.NET MVC Grid Documentation
- ASP.NET MVC Grid Demos
- ASP.NET MVC Grid Product Page
- Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)
- Telerik UI for ASP.NET MVC Forums