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;
}
}