在这种情况下如何获取父值(使用 Telerik Panel Bar)

发布于 2024-10-07 10:42:38 字数 1392 浏览 0 评论 0原文

使用 telerik 面板栏

Html.Telerik().PanelBar()
    .Name("PanelBar")
    .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;
                }));
    })

http://www .telerik.com/help/aspnet-mvc/telerik-ui-components-panelbar-data-binding.html

我需要的是根据 categoryID生成一个 URL ProductID

即:

.Children(category => category.Products));
    mappings.For<Product>(binding => binding
            .ItemDataBound((item, product) =>
            {
                item.Text = product.ProductName;
                item.Url = (Get at the parent to get the categoryid somehow) + "/Details/" + product.productID;
            }));

但我不知道如何访问任何类别字段。

我无法从产品中获取它,因为它将是一对多,并且我将拥有 product.Categories. linq 方法

干杯

Using telerik Panel Bar

Html.Telerik().PanelBar()
    .Name("PanelBar")
    .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;
                }));
    })

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-panelbar-data-binding.html

What I need is to generate a URL based on categoryID and productID

i.e. :

.Children(category => category.Products));
    mappings.For<Product>(binding => binding
            .ItemDataBound((item, product) =>
            {
                item.Text = product.ProductName;
                item.Url = (Get at the parent to get the categoryid somehow) + "/Details/" + product.productID;
            }));

But I can't figure out how I can access any of the category fields.

And I can't get it from product because it will be one-many, and i'll have product.Categories. linq methods

Cheers

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

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

发布评论

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

评论(1

伴随着你 2024-10-14 10:42:38

尽管我不想,但我设法像这样存储该值:

mappings.For<Category>(binding => binding
                .ItemDataBound((item, category) =>
                {
                    item.Text = category.CategoryName;
                    item.ActionName = category.CategoryID.ToString();
                })
                .Children(category => category.Products));
        mappings.For<Product>(binding => binding
                .ItemDataBound((item, product) =>
                {
                    item.Text = product.ProductName;
                    item.Url = item.Parent.ActionName + "/Detail/" + product.ProductID;
                }));

想知道是否有人最终得到了更干净的解决方案

Although I didn't want to, I managed to store the value like this:

mappings.For<Category>(binding => binding
                .ItemDataBound((item, category) =>
                {
                    item.Text = category.CategoryName;
                    item.ActionName = category.CategoryID.ToString();
                })
                .Children(category => category.Products));
        mappings.For<Product>(binding => binding
                .ItemDataBound((item, product) =>
                {
                    item.Text = product.ProductName;
                    item.Url = item.Parent.ActionName + "/Detail/" + product.ProductID;
                }));

Wonder if anyone ends up with a cleaner solution

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