treeView MVC 扩展的问题

发布于 2024-11-02 09:23:01 字数 884 浏览 6 评论 0 原文

我正在 MVC 中使用 treeView 数据绑定,并且收到以下错误:

错误 1 ​​无法使用 lambda 表达式作为动态分派操作的参数,而不先将其转换为委托或表达式树类型

当我尝试运行演示代码时:

 <% 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(); %>

我读到可能缺少程序集,因此我添加了 Linq 程序集:

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

仍然遇到同样的问题,有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

<逆流佳人身旁 2024-11-09 09:23:01
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Category>>" 

这就是答案,什么通过 System.Web.Mvc.ViewPage 传递。应该是我们正在映射的类。

<%@ 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.

抱猫软卧 2024-11-09 09:23:01
<%@ 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>

您需要正确拥有类结构,否则树视图将不会呈现(子项的类结构)

页面应继承:

Inherits="System.Web.Mvc.ViewPage 类的 IEnumerable 列表/对象

<%@ 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文