0

I'm working with a treeView data Binding in MVC, and I'm getting the following error:

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

When I try to run the demo code:

 <% Html.Telerik().TreeView()


 .Name("TeleTreeView")
    .BindTo(Model, mappings => 
    {
         mappings.For<Category>(binding => binding
        .ItemDataBound((item, category) =>
        {
            item.Text = category.CategoryName;
        })
        .Children(category => category.Products));
         mappings.For<Product>(binding => binding
        .ItemDataBound((item, product) =>
        {
            item.Text = product.ProductName;
       }));
})
   .Render(); %>

I've read that maybe I'm missing an assembly so I've added the Linq one:

<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

Still having the same problem, any suggestions?

2 Answers 2

1
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Category>>" 

This is the answer, What's passing through System.Web.Mvc.ViewPage. Should be the class we're mapping.

Sign up to request clarification or add additional context in comments.

Comments

0
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<GridWithWindow.Jar>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    AddEditUser
</asp:Content>

    <% using (Html.BeginForm("AddEditUser", "JarUser", FormMethod.Post ))
       {%>

        <% List<TreeViewItem> checkedNodes = ViewData["TreeView1_checkedNodes"] as
            List<TreeViewItem>; %>


    <%= Html.Telerik().TreeView()
    .Name("Tree")
    .ShowCheckBox(true)
    )
    .BindTo(Model, mappings =>
    {
        mappings.For<GridWithWindow.Jar>(binding => binding
            .ItemDataBound((item, jag) =>
                {
                    item.Text = jag.TreeName;
                    item.Value = jag.TreeName;

                    if (checkedNodes != null)
                    {
                        var checkedNode = checkedNodes
                                            .Where(e => e.Value.Equals("ddd"))
                                            .FirstOrDefault();
                        item.Checked = checkedNode != null ? checkedNode.Checked : false;
                    }
                    item.Expanded = true;

                })
                .Children(jag => jag.FirstLevelIList));
        mappings.For<GridWithWindow.Jar.FirstLevel>(binding => binding
            .ItemDataBound((item, frst) =>
                {
                    item.Text = frst.FirstLevelName;
                    item.Value = frst.FirstLevelName;
                })
                .Children(frst => frst.SecondLevelList));
        mappings.For<GridWithWindow.Jar.FirstLevel.SecondLevel>(binding => binding
            .ItemDataBound((item, scnd) =>
            {
                item.Text = scnd.SecondLevelName;
                item.Value = scnd.SecondLevelName;
            })
             .Children(scnd => scnd.ThirdlevelList));
        mappings.For<GridWithWindow.Jar.FirstLevel.SecondLevel.Thirdlevel>(binding => binding
            .ItemDataBound((item, thrd) =>
            {
                item.Text = thrd.ThirdlevelName;
                item.Value = thrd.ThirdlevelName;
            })
             .Children(thrd => thrd.AEDV_List));
        mappings.For<GridWithWindow.UserAcces>(binding => binding
            .ItemDataBound((item, acs) =>
            {
                item.Text = acs.UserAccesName;
                item.Value = acs.UserAccesName;
            })
           );
    })%>
    <input type="submit" value="GO" id="btn" />
    <input type="button" id="pst" value="do post back" onclick="javascript:__doPostBack()" />
    <%} %>

    <style type="text/css">
        .event-log-wrap
        {
            float: left;
            display: inline;
            width: 468px;
            margin-left: 10em;
        }
    </style>

</asp:Content>

You need to have the class structures properly or else treeview will not be rendered (class structures for the children items)

The Page should inherit:

Inherits="System.Web.Mvc.ViewPage<IEnumerable<GridWithWindow.Jaguar> an IEnumerable list/obj of your class

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.