Access parent item value in child binding

3 posts, 1 answers
  1. Donna Stewart
    Donna Stewart avatar
    127 posts
    Member since:
    Apr 2009

    Posted 06 Jan 2014 Link to this post

    I need the parent's item while binding the child item setting it's action.  I need to pass the categoryName from the category (parent) on the child action call.  Is this possible?  If so, how?  Any help is very much appreciated!

    Here is the panelbar code:
    @(Html.Kendo().PanelBar()
    .Name("MainMenu")
    .ExpandMode(PanelBarExpandMode.Single)
    .BindTo(Model, mappings =>
        {
            mappings.For<GMCWeb.Areas.bi.Models.ReportCategory>(binding => binding
                .ItemDataBound((item, category) =>
                    {
                        item.Text = "<div class='row'><div class='col-md-9'>" + category.categoryName + "</div><div class='col-md-3 menu-arrow'><i class='fa fa-arrow-circle-right fa-2x'></i></div></div>";
                        item.Encoded = false;
                    })
                    .Children(category => category.reportCategories));
            mappings.For<GMC.CustomerInformation.DashboardParameters.ReportCategoryInformation>(binding => binding
                .ItemDataBound(
                (item, reportCategory) =>
                   {
                   item.Text = reportCategory.ReportCategoryName;
                   item.Enabled = !reportCategory.Disabled;
                   item.Action("GetReports", "Home", new RouteValueDictionary { { "category", category.categoryName } });
                   }));    
        }))
  2. Answer
    Donna Stewart
    Donna Stewart avatar
    127 posts
    Member since:
    Apr 2009

    Posted 08 Jan 2014 Link to this post

    Hello Donna,

    The MenuItem has a reference to its parent through the Parent property. You can get the parent menu item like this:
    .ItemDataBound((item, product) =>
    {
        var parent = item.Parent;
                             
        item.Text = product.ProductName + " " + parent.Enabled.ToString();
    }));

    At this point the parent data item (in your case category) is no longer available. The only way to retrieve it is to find it manually.

    Regards,
    Georgi Krustev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Donna Stewart
    Donna Stewart avatar
    127 posts
    Member since:
    Apr 2009

    Posted 08 Jan 2014 Link to this post

    Thank you!
Back to Top