Reputation: 961
I have a fairly simple data model with three tables.. Contracts, Members, Episodes. And am trying to build a telerik treeview to show every entry in the three tables with respect to their relationship in tiers of the tree...
As a note, the telerik demo only shows one section of children. Telerik's Online Demo
Additionally, their Drag and Drop demo uses the same tables and simply uses a GetRootEmployee function to pupulate. So I can't find any relevant examples.
Contract 1's decription
Member of Contract 1's name
Episodeid of Member in Contract 1
Another Member of Contract 1...
Episodeid of another Member.
Contract 2's description
The problem is that I simply cannot get the episodes (third tier) to populate successfully, though the first two work fine. I will post my View, and my controller.
@(
Html.Telerik().TreeView()
.Name("myTree")
.BindTo(Model, mappings =>
{
mappings.For<SMTXEFMVCModel.Contract>(binding => binding
.ItemDataBound((item, contract) =>
{
item.Text = contract.Description;
})
.Children(contract => contract.Members));
mappings.For<SMTXEFMVCModel.Member>(binding => binding
.ItemDataBound((item, member) =>
{
item.Text = member.FirstName + " " + member.LastName;
}) //If I stop here, it populates Contract and Members correctly.
.Children(member => member.Episodes));
mappings.For<SMTXEFMVCModel.Episode>(binding => binding
.ItemDataBound((item, episode) =>
{
item.Text = episode.episodeID;
}));
})
)
public ActionResult TreeView()
{
var ctx = new SMTXContext();
var Contracts = ctx.Contracts.ToList();
return View(Contracts);
}
Upvotes: 2
Views: 2808
Reputation: 961
Looks like the problem was a datatype mixup.
item.Text = episode.episodeID;
should have been
item.Text = episode.episodeID.ToString();
then it works flawlessly.
Upvotes: 1
Reputation: 17794
your third mapping seems to be buggy
mappings.For<SMTXEFMVCModel.Member>(binding => binding
.ItemDataBound((item, episode) =>
{
item.Text = episode.episodeID;
}));
shouldn't it define mapping for Episode rather than Member. Furthermore there is no need for
var Members = ctx.Members.ToList();
var Assessments = ctx.Assessments.ToList();
when you are not passing these values to view in any way possible like
return View(Contracts);
Treeview will automatically traverse through Members and Episodes objects through navigational properties of Contract and Member object.
Upvotes: 0