开发者

How to get parent value in this situation (using Telerik Panel Bar)

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/h开发者_如何学Pythonelp/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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜