我有問題的數據綁定多個表中的一個兒童teir。所以說例如我有5張桌子。Telerik Treeview DataBinding
contracts
members
phoneassessments
homeassessments
personalassessments
每個評估表具有參考MEMBERID,我需要打印所有三種類型的分層評估的直屬會員,換句話說就是這個樣子。
Contract 1
Member 1
Home Assessment 1
Home Assessment 2
Phone Assessment 1
Personal Assessment 1
etc
Member 2
我的代碼是...
Html.Telerik().TreeView()
.Name("TreeName")
.BindTo(Model, mappings =>
{
mappings.For<SMTXEFMVCModel.Contract>(binding => binding
.ItemDataBound((item, contract) =>
{
item.Text = contract.Description;
item.SpriteCssClasses = ("icon-contracts");
})
.Children(Contract => Contract.Members));
mappings.For<SMTXEFMVCModel.Member>(binding => binding
.ItemDataBound((item, member) =>
{
item.Text = member.FirstName + " " + member.LastName;
item.SpriteCssClasses = ("icon-members");
}));
})
)
所以我的問題是,下一步怎麼走?語法是什麼?
我不禁想起它會看起來像這樣。
Html.Telerik().TreeView()
.Name("TreeName")
.BindTo(Model, mappings =>
{
mappings.For<SMTXEFMVCModel.Contract>(binding => binding
.ItemDataBound((item, contract) =>
{
item.Text = contract.Description;
item.SpriteCssClasses = ("icon-contracts");
})
.Children(Contract => Contract.Members));
mappings.For<SMTXEFMVCModel.Member>(binding => binding
.ItemDataBound((item, member) =>
{
item.Text = member.FirstName + " " + member.LastName;
item.SpriteCssClasses = ("icon-members");
{)
.Children(Members => Members.Assessments));
mappings.For<(SMTXEFMVCModel.HomeAssessments,SMTXEFMVCModel.PhoneAssessments,
SMTXEFMVCModel.PersonalAssessments)>(binding => binding
.ItemDataBound((item, assessments) =>
{
item.Text = HomeAssessments.AssessmentID.ToString()
item.Text = PhoneAssessments.AssessmentID.ToString()
item.Text = PersonalAssessments.AssessmentID.ToString()
}));
})
)
下面是我的控制器
public ActionResult TreeView()
{
var ctx = new SMTXContext();
var Contracts = ctx.Contracts.ToList();
return View(Contracts);
}
,我在我看來使用作爲一個IEnumerable強類型從模型中的表相關的ActionResult。 (下面的線是在我看來,第一行
@model IEnumerable<SMTXEFMVCModel.Contract>
這對你很狡猾,對條件有很好的思考。很高興你找到了適合你的方法。 –