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

[Solved] Grid dynamic Binding

0 Answers 53 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.
Yuliang
Top achievements
Rank 1
Yuliang asked on 04 Dec 2011, 06:02 AM
Hi, I saw there was solution to bind the dynamic objects to Grid, but I used the solution to bind, it threw exception.
Code:
Html.Telerik().Grid<dynamic>(Model.Select(n => new { n.ID, n.ItemID, n.Title, n.Name, n.VersionID }).ToList())
                         .Name("Grid")
                         .ToolBar(f => f.Position(GridToolBarPosition.Both).Custom().Action("Add", "TelerikNews", null).Text("Add"))
                         .Columns(columns =>
                         {
                             columns.Bound("ItemID");
                             columns.Bound("VersionID");
                             columns.Bound("Name");
                             columns.Bound("Title");
                             columns.Template(n =>
                             {
                                 %>
                                    <%=Html.ActionLink("Edit", "Edit", new { id = ( n as dynamic) .ID })%>
                                    <%=Html.ActionLink("Delete", "Delete", new { id = (n as dynamic).ID }, new { onclick = "return confirm('Are you sure to delete this item?');" })%>
                                 <%
                             });
                         })
                         .PrefixUrlParameters(false)
                         .DataBinding(c => c.Server())
                         .Pageable(g => g.PageSize(6)
                                       .Position(GridPagerPosition.Both)
                                       .Style(GridPagerStyles.Numeric))
                         .Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn));

And the exception likes:

Invalid property or field - 'ItemID' for type: Object

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid property or field - 'ItemID' for type: Object

Source Error:

Line 26: if (memberInfo == null) Line 27: { Line 28: throw new ArgumentException(FormatInvalidTokenErrorMessage(token, instance.Type)); Line 29: } Line 30: 

Source File: E:\Telerik.Web.Mvc\Infrastructure\Implementation\Expressions\MemberAccess\Tokenizer\MemberAccessTokenExtensions.cs Line: 28

Can anyone help me to explain what's wrong?
Thanks a lot.

Tags
Grid
Asked by
Yuliang
Top achievements
Rank 1
Share this question
or