This is a migrated thread and some comments may be shown as answers.

[Solved] Dynamic binding with asp.net view engine?

1 Answer 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Patrik
Top achievements
Rank 1
Patrik asked on 16 May 2011, 09:05 AM
Hello!

I saw in another post that it was possible to bind to a dynamic object < http://www.telerik.com/community/forums/aspnet-mvc/grid/dynamic-type-with-grid.aspx >.

Does it only work with Razor? Because when i try to use it with the asp.net view engine i get the following error:
RuntimeBinderException
'object' does not contain a definition for 'Text'

This is the view:
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<dynamic>>" %>
 
<%= Html.Telerik().Grid<dynamic>(Model)
        .Name("Test")
        .Columns(columns =>
        {
            columns.Bound("Text");
            columns.Bound("Id");           
        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_BasicDropdownGridBinding", "Grid"))
        .EnableCustomBinding(true)
        .Pageable(paging => paging.Total(ViewBag.ItemCount ?? 0).PageSize(10))
        .Sortable()
     %>

and the controller:
public ActionResult BasicDropdownGrid()
{
    IEnumerable<dynamic> data = _BasicDropdownGridGetData(new GridCommand { PageSize = 10 });
    ViewBag.ItemCount = 100;
    return View(data);
}
 
[GridAction(EnableCustomBinding = true)]
public ActionResult _BasicDropdownGridBinding(GridCommand command)
{
    IEnumerable<dynamic> data = _BasicDropdownGridGetData(command);
    return View(new GridModel { Data = data, Total = 100 });
}
 
private IEnumerable<dynamic> _BasicDropdownGridGetData(GridCommand command)
{
    IEnumerable<Item> data = dbGetItems((command.Page - 1), command.PageSize);
    return data.Select(x => new { Id = x.Id, Text = x.Text }).ToList();
}

When i debug, i can clearly see that the model contains an object that looks like a list with Text/Id elements.

1 Answer, 1 is accepted

Sort by
0
alex
Top achievements
Rank 1
answered on 08 Dec 2011, 01:04 PM
Hi. I have a same issue. Did you fix that problem? And how.
Thanks a lot
Tags
Grid
Asked by
Patrik
Top achievements
Rank 1
Answers by
alex
Top achievements
Rank 1
Share this question
or