0
votes

My model is an IEnumerable which I would like to bind to a telerik mvc grid. Additionally the grid should auto-generate the columns and display everything from my dynamic object.

I found several posts on the telerik forum regarding this topic, like here: http://www.telerik.com/community/forums/aspnet-mvc/general/dynamically-generate-grid-columns.aspx

Unfortunately the result is the same: the grid displays the number of total rows in the footer but no rows are shown.

Any ideas?

Update: I attached a sample project on the telerik forum: http://www.telerik.com/community/forums/aspnet-mvc/grid/auto-generate-grid-columns-with-collection-of-dynamic-objects-as-model.aspx

Update: Here's sample code to try it out:

Index.cshtml:

@model IEnumerable<dynamic>
@(
    Html.Telerik().Grid(Model).Name("Grid")
                .Columns(columns => columns.AutoGenerate(true))
                .Pageable()
                .Sortable()
                .Groupable()
                .Filterable()
)

HomeController.cs:

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(GetStaticData());
        }

        private static IEnumerable<dynamic> GetStaticData()
        {
            dynamic products = new[]
                                    {
                                         new { ProductID = 1, ProductName = "Motor" },
                                         new { ProductID = 2, ProductName = "Converter" },
                                         new { ProductID = 3, ProductName = "Transformer" }
                                    };

            return products; 
        }
    }
1
Please post come code (view, model, controller) thanks,Michael Grassman
I posted some sample code and also a link to my post in the telerik forum where I attached a sample project.TheFitGeekGirl

1 Answers

1
votes

This post seems to say that it's not supported. http://www.telerik.com/community/forums/aspnet-mvc/grid/display-dynamic-objects-in-grid.aspx

This post says that you can overload the columns binding and passing in the propery name.

http://www.telerik.com/community/forums/aspnet-mvc/grid/dynamic-view-with-grid.aspx

Looks like you can use dynamic data but not auto generated columns.

Thanks,