This is a migrated thread and some comments may be shown as answers.
How to implement complex Ajax Binding ?
0 Answers 64 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Cookie Monster
Top achievements
Rank 1
Cookie Monster asked on 21 Apr 2010, 04:00 AM
Hello, I have a complex TreeView and I need to put a 'LoadOnDemand' functionality in place.. Could you please help me with the syntax a bit ?
Here is what I did, but in the debug mode Ajax method does not get hit..
VIEW:

Html.Telerik().TreeView()
            .Name("HierarchyView")
            .ClientEvents(events => events
                                        .OnCollapse("updateTreeViewState")
                                        .OnExpand("updateTreeViewState"))
            .BindTo(Model, mappings =>
            {
                mappings.For<Division>(binding => binding
                        .ItemDataBound((item, branch) =>
                        {
                            item.Text = branch.Name;
                            item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
                            item.LoadOnDemand = true;
                        })
                        .Children(branch => branch.Branches)
                        );
                mappings.For<Region>(binding => binding
                        .ItemDataBound((item, branch) =>
                        {
                            item.Text = branch.Name;
                            item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
                            item.LoadOnDemand = true;
                        })
                        .Children(branch => branch.Branches)
                        );
                mappings.For<ProfitCentre>(binding => binding
                        .ItemDataBound((item, branch) =>
                        {
                            item.Text = branch.Name;
                            item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
                            item.LoadOnDemand = true;
                        })
                        .Children(branch => branch.RMs)
                        );
                mappings.For<User>(binding => binding
                        .ItemDataBound((item, rm) =>
                        {
                            item.Url = Url.Action("StartBrowseAs", "Account", new {rmId = rm.Id});
                            
                            item.Text = rm.FullName;
                            item.Value = rm.FullName;
                            item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Url);

                            item.Content = () =>{ Html.RenderPartial("~/Views/Account/TreeMenu.ascx", rm);};
                        })
                        .Children(user => null)
                        );
            })
            .DataBinding(dataBinding => dataBinding
                .Ajax().Select("_AjaxGetSubordinateTreeView", "Account"))
            .Render();

CONTROLLER:
        [HttpGet]
        public ActionResult GetSubordinateTreeView()
        {
            IEnumerable<HierarchyElement> branches = null;
            .. // populate 'branches'
            return PartialView("SubordinateTreeView", branches);
        }

        [HttpPost]
        public ActionResult _AjaxGetSubordinateTreeView(TreeViewItemModel node)
        {
            IEnumerable<HierarchyElement> branches = null;
            ... // populate 'branches'
             return new JsonResult { Data = branches };
        }
Tags
TreeView
Asked by
Cookie Monster
Top achievements
Rank 1
Share this question
or