I am trying to work with Telerik Treeview in MVC with C#.
I have 3 models and need just 2 levels (root and child) of nodes.
I need that the root node is the First Model, and the child node the Third Model.
Both are linked by the Second Model.
Below is the code that I have done:
@using Hant.Material.ValueObject.Domain
@using Hant.Material.Web.Models
@model IEnumerable<DescriptivePatternModel>
@{
Html.Telerik().TreeView()
.Name("treeView")
.ExpandAll(true)
.BindTo(Model, mapping => mapping
.For<DescriptivePatternModel>(binding => binding
.Children(descriptivePattern => descriptivePattern.Items)
.ItemDataBound((i, descriptivePattern) =>
{
i.Text = descriptivePattern.Name;
i.Value = descriptivePattern.Id.ToString();
})
)
.For<ItemModel>(binding => binding
.ItemDataBound((i, item) =>
{
i.Text = item.VersionDate.ToString();
i.Value = item.Id.ToString();
})
)
).Render();
}
In this code I can only access the Second Model.
I had the same issue. You need something to return a json result from your controller. Create a TreeViewItem in your action method, bind it and return it as a jsonresult. Notice how treeview items are returned. You may just return the treeviewitem depending on your case.
eg: