This is a migrated thread and some comments may be shown as answers.

[Solved] Binding to Model Using .ItemDataBound Not Working!

3 Answers 61 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Darin
Top achievements
Rank 1
Darin asked on 19 Jan 2012, 10:18 PM
This code:

@{Html.Telerik().TreeView()
    .Name("TreeView")
    .BindTo((IEnumerable)Model, mappings =>
    {
        mappings.For<NavigationTreeNode>(binding => binding
                .ItemDataBound((item, node) =>
                {
                    item.Text = node.ShortTitle;
                    item.Expanded = true;
                })
                .Children(node => node.Children));
    });
}

Produces only this output:

  • Item 1
    • Sub item 1
    • Sub item 2
    • Sub item 3
    • Sub item 4
  • Item 2
  • Item 3
  • Item 4

Why?

Thanks, Darin

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 23 Jan 2012, 09:00 AM
Hi Darin,

Could you please share us more details about the problem you have ? In order to assist you I will need code snippets used for the model,controller and the view or a sample project. Also please give an example what should be the expected result.
Thank you for the assistance and the cooperation.

All the best,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Darin
Top achievements
Rank 1
answered on 24 Jan 2012, 09:45 PM
Controller:

    public class HomeController : Controller
    {
        //
        // GET: /Home/
 
        public ActionResult Index()
        {
            return View(NavigationTree.Root.Children);
        }
 
    }

Model:

    public class SiteMapViewModel
    {
        public IEnumerable<NavigationTreeNode> Nodes { getset; }
        public NavigationTreeNode SelectedNode { getset; }
 
        public SiteMapViewModel()
        { 
        
        }
    }

    public class NavigationTreeNode
    {
        public int Id { getprotected set; }
        public int ParentId { getprotected set; }
 
        public string Title { getprotected set; }
        public string ShortTitle { getprotected set; }
        public string FileName { getprotected set; }
        public string Permalink { getprotected set; }
 
        public bool RouteByTreePath { getprotected set; }
        public bool RouteByPermalink { getprotected set; }
        public bool ShowInNavMenu { getprotected set; }
        public bool ShowInSiteMap { getprotected set; }
 
        public int SortOrder { getprotected set; }
 
        public string ControllerName { getprotected set; }
        public string ActionName { getprotected set; }
 
        public bool Active { getprotected set; }
        public bool Locked { getprotected set; }
...

View:

@model IEnumerableNavigationTreeNode>
@using Sunstone.WebSite
@using Telerik.Web.Mvc.UI
@using System.Collections
 
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{Html.Telerik().TreeView()
    .Name("TreeView")
    .BindTo((IEnumerable)Model, mappings =>
    {
        mappings.For<NavigationTreeNode>(binding => binding
                .ItemDataBound((item, node) =>
                {
                    item.Text = node.ShortTitle;
                    item.Expanded = true;
                })
                .Children(node => node.Children));
    });
}

0
Darin
Top achievements
Rank 1
answered on 25 Jan 2012, 11:00 PM
I take it back - I did not figure this out.  For some reason, it just will not bind to the treeview.

Any help is appreciated.
Tags
TreeView
Asked by
Darin
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Darin
Top achievements
Rank 1
Share this question
or