New to Telerik UI for ASP.NET MVCStart a free 30-day trial

Bind Grid to Collections of Dynamic Objects

Environment

ProductTelerik UI for ASP.NET MVC Grid
Product version2025.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:

  1. 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
    )
  2. 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

See Also