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

TreeView BindTo Get Cannot use lamda expression error

3 Answers 70 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Aleksander
Top achievements
Rank 1
Aleksander asked on 02 Jul 2012, 09:26 PM
So I have the following for my Tree

@{ Html.Telerik().TreeView().Name("tvContacts")
       .BindTo(ViewBag.Contacts, mappings =>
       {
           mappings.For<ContactSite>(binding => binding
               .ItemDataBound((item, site) =>
               {
                   item.Text = site.SiteName;
               })
               .Children(site => site.ContactGroups));
           mappings.For<ContactGroup>(binding => binding
               .ItemDataBound((item, group) =>
               {
                   item.Text = group.GroupName;
               })
               .Children(group => group.ContactPeople));
           mappings.For<ContactPerson>(binding => binding
               .itemDataBound((item, person) =>
               {
                   item.Text = person.FirstName + " " + person.LastName;
               }));
       });
}

Then I have the following for my objects

using System;
using System.Collections.Generic;
using System.Linq;
 
namespace OnCallTracker.Business
{
    public class ContactPage
    {
        public IEnumerable<ContactSite> ContactSites { get; set; }
    }
 
    public class ContactSites : List<ContactSite>
    {
    }
 
    public class ContactSite
    {
        public int SiteId { get; set; }
        public string SiteName { get; set; }
        public IEnumerable<ContactGroup> ContactGroups { get; set; }
    }
 
    public class ContactGroups : List<ContactGroup>
    {
    }
 
    public class ContactGroup
    {
        public int GroupId { get; set; }
        public string GroupName { get; set; }
        public string GroupDescription { get; set; }
        public ContactPerson Manager { get; set; }
        public IEnumerable<ContactPerson> ContactPeople { get; set; }
    }
 
    public class ContactPeople : List<ContactPerson>
    {
    }
 
    public class ContactPerson
    {
        public int PersonProfileId { get; set; }
        public Int64 PersonnelId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string PersonnelName { get; set; }
        public string CellNumber { get; set; }
        public string DeskNumber { get; set; }
 
        public string GetContactPersonName()
        {
            return FirstName + " " + LastName;
        }
    }
}

Can you please tell me what I'm missing? I get the following error.

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

Source Error:

Line 4:  
Line 5:  @{ Html.Telerik().TreeView().Name("tvContacts")
Line 6:         .BindTo(ViewBag.Contacts, mappings =>
Line 7:         {
Line 8:             mappings.For<ContactSite>(binding => binding

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 04 Jul 2012, 05:48 AM
The error indicates that there is a syntax error in the lambda expression.

It seems that the last itemDataBound causes the issue -- it should be in PascalCase, ItemDataBound, like in the other mappings.

All the best,
Alex Gyoshev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Aleksander
Top achievements
Rank 1
answered on 05 Jul 2012, 03:54 PM
Ok I have changed this to PascalCase and I still get the same error. Anything else I'm missing?
0
Alex Gyoshev
Telerik team
answered on 10 Jul 2012, 09:02 AM
Determine which of the mappings causes the error by using only one mapping at a time. Deleting most of the code will let you isolate the issue.

Also, make sure that the System.Data.Linq namespace is included in the view.

Greetings,
Alex Gyoshev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
TreeView
Asked by
Aleksander
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Aleksander
Top achievements
Rank 1
Share this question
or