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

Error: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

7 Answers 4887 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.
Will Yeung
Top achievements
Rank 1
Will Yeung asked on 24 Feb 2010, 07:12 AM
Hi, 

Thanks for the great product! :)
After upgrading from 2009 Q3 to 2010 Q1 and MVC rc1 to MVC rc2, my this expression has error:

Html.Telerik().Grid(Model)
        .Name("ASSETGrid")
         .Columns(columns =>
         {
             columns.Bound(x => x.TX_TYPE).Title("Type");
             columns.Bound(x => x.TX_REFNO).Title("Ref");
             columns.Bound(x => x.DESCRIPTION).Title("Desc");
             columns.Bound(x => x.CREATOR).Title("Creator");
             columns.Bound(x => x.CREATION_DATE.ToString("yyyy-MM-dd")).Title("Created");
             columns.Bound(x => x.LAST_UPDATE_DATE).Format("{0:yyyy-MM-dd}").Title("Last updated");
             columns.Bound(x => x.TX_STATUS).Title("Status");
             columns.Bound(x =>
                 (x.CurrentState.CanSelect(AppHelper.GetCurrentUser(), AppHelper.GetCurrentUserRole()) ? Html.ActionLink("Select", "SelectAsCurrent", new { TX_KEY = x.TX_KEY }).ToString() : Html.ActionLink("Details", "Details", new { TX_KEY = x.TX_KEY }).ToString()) + " " +
                 (x.CurrentState.CanAccept(AppHelper.GetCurrentUser(), AppHelper.GetCurrentUserRole()) ? Html.ActionLink("Accept", "Accept", new { TX_KEY = x.TX_KEY }).ToString() + " " : "") +
                 (x.CurrentState.CanCancel(AppHelper.GetCurrentUser(), AppHelper.GetCurrentUserRole()) ? Html.ActionLink("Cancel", "Cancel", new { TX_KEY = x.TX_KEY }).ToString() + " " : "") +
                 (x.CurrentState.CanReject(AppHelper.GetCurrentUser(), AppHelper.GetCurrentUserRole()) ? Html.ActionLink("Reject", "Reject", new { TX_KEY = x.TX_KEY }).ToString() + " " : "") +
                 (x.CurrentState.CanReturn(AppHelper.GetCurrentUser(), AppHelper.GetCurrentUserRole()) ? Html.ActionLink("Return", "Return", new { TX_KEY = x.TX_KEY }).ToString() + " " : "") +
                 (x.CurrentState.CanSubmit(AppHelper.GetCurrentUser(), AppHelper.GetCurrentUserRole()) ? Html.ActionLink("Submit", "Submit", new { TX_KEY = x.TX_KEY }).ToString() + " " : "") +
                 ""
                 ).Encoded(false).Title("Action");
         })
        //.Filterable()
        .Pageable()
        .Sortable()
        .Render();




InvalidOperationException occurred, 
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

in line 49, UI\Grid\Columns\GridBoundColumn.cs file
#if MVC2
            Metadata = ModelMetadata.FromLambdaExpression(expression, new ViewDataDictionary<TModel>()); (<<----- error)
            Title = Metadata.DisplayName;
            Format = Metadata.DisplayFormatString;
            Visible = Metadata.ShowForDisplay;
#endif
    

it seems I cannot use expression anymore~~ :(
Looking forward to hearing from you

Thanks~

Best wishes, always
Billy



7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Feb 2010, 07:33 AM
Hello Will Yeung,

Indeed we now support only member expressions (due to MVC2 Metadata requirements). As a workaround I suggest you use the Template property to specify how you want your data displayed:

Old:
columns.Bound(x => x.CREATION_DATE.ToString("yyyy-MM-dd"))
New"
columns.Bound(x => x.CREATION_DATE).Template(x => {
%>
           <%= x.CREATION_DATE.ToString("yyyy-MM-dd") %>
<%
});

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Will Yeung
Top achievements
Rank 1
answered on 24 Feb 2010, 08:22 AM
wowowo Atanas Korchev

you answer is super fast!

Excellent work around! you solved my problem.

Thank you very much! :)
0
Guillaume
Top achievements
Rank 1
answered on 03 Mar 2010, 10:44 AM
I got the same error. The following code :
<%= Html.Telerik().Grid(Model) 
        .Name("Termes") 
             .DataBinding(dataBinding => dataBinding 
                    .Ajax() 
                        .Select("EditingServerSide", "Termes") 
                        .Insert("Ajouter", "Termes") 
                        .Update("Sauver", "Termes") 
                        .Delete("Effacer", "Termes") 
            ) 
        .DataKeys(keys =>  
        { 
            keys.Add(t=>t.ID); 
        }) 
        .Toolbar(commands => commands.Insert()) 
        .Columns(columns => 
        { 
            columns.Bound(t=>t.TexteCourt).Width(100); 
            columns.Bound(t=>t.TexteLong).Width(500); 
            columns.Command(commands => 
            { 
                commands.Edit(); 
                commands.Delete(); 
            }).Width(180); 
        }) 
        .Pageable() 
        .Sortable() 
         
%> 
fails with the title error.

It works if I remove the command columns..
0
Marco
Top achievements
Rank 1
answered on 03 Mar 2010, 11:35 AM
Hello Guillame,

did you found something? 

i'm facing the same error :(

this is my grid 
 <% Html.Telerik().Grid(Model) 
            .Name("Grid") 
            .Toolbar(commands => commands.Insert()) 
            .DataKeys(dataKeys => dataKeys.Add(o => o.id)) 
            .Columns(columns => 
            { 
                columns.Bound(o => o.idUnidade).Title("Unidade(s)"); 
                columns.Bound(o => o.descricao).Width(300); 
                columns.Bound(o => o.data).Width(100); 
                columns.Bound(o => o.QtdRefDiarias).Width(80); 
                columns.Template(o => 
                {  
                    %> 
                    <href="<%= Url.Action("EmentasPratos", "Ementas", new {IdEmenta = o.id })%>" title="Pratos"><img src="../../Content/images/detail.png" style="border:none;"  /></a
                    <%  
                }).Title("Pratos"); 
                columns.Command(commands => commands.Edit()).Width(200); 
            }) 
            .DataBinding(dataBinding => dataBinding 
                .Server() 
                    .Update("Update", "Ementas") 
                    .Select("Create", "Ementas") 
                    .Insert("Insert", "Ementas")) 
            .Pageable() 
            .Sortable() 
            .Filterable() 
            .Render(); 
    %> 

and if i remove edit command it work....what could be wrong?
on controller i just pass a List<DTO>  

return view(List<DTO>)

Best Regards
0
Accepted
Atanas Korchev
Telerik team
answered on 03 Mar 2010, 11:41 AM
Hi Marco,

You can check this forum thread.

Best wishes,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Guillaume
Top achievements
Rank 1
answered on 03 Mar 2010, 12:03 PM
Thanks !
0
Marco
Top achievements
Rank 1
answered on 03 Mar 2010, 12:18 PM
Thanks again Atanas.

Best Regards
Tags
Grid
Asked by
Will Yeung
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Will Yeung
Top achievements
Rank 1
Guillaume
Top achievements
Rank 1
Marco
Top achievements
Rank 1
Share this question
or