@(
Html.Kendo().TreeView()
.Name(
"treeView"
)
.BindTo(Model, mapping =>
mapping.For<SomeViewModel>(binding =>
binding.ItemDataBound((item, viewModel) =>
{
item.Text = viewModel.DisplayName;
})
.Children(viewModel => viewModel.Children)))
.TemplateId(
"some-template"
)
)
Specifying the template like that has no impact on the node at all. I also noticed in ItemDataBound the NavigationItem (item) has a Template property but I'm not sure what to set on it (nothing I tried worked). I also tried the Html property, but that messes up the bindings. How can I define a template?
7 Answers, 1 is accepted
Templates and server-side binding do not work well together at this moment. You can use templates only with a datasource binding.
All the best,Alex Gyoshev
the Telerik team
I came up with the same issue today. The last version of kendo UI doesn't seam to have solved this problem.
Am I missing something ? Is it planed to make this work in a near future ?
Thanks
Nby.
Hello Nby,
The last few releases of the UI for ASP.NET MVC work with BindTo + Templates, as they serialize the data to the client and use the client-side rendering along with the template. If this does not work in your application, please open a support ticket and provide a runnable reproduction sample that shows the problem.
Regards,Alex Gyoshev
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I've read the initial question too fast. In fact, my problem is a bit different. The template works fine, but i woud like to use properties of my viewmodel in the template.
In the sample below, the properties of the datasource, like "dept" or "owner" can be used in the template.
http://jsfiddle.net/trentballew/oc9qsnyc/6/
But when using BindTo, the only item properties available in the template are text and id. Is there a way to set custom properties of my viewmodel to the item in the BindTo, and to use them in the client template ?
Thank you
Nby.
Hello Nby,
No, I'm afraid not. The BindTo binding is primarily targeted at server-side rendering (with the exception when using templates). At this time, the best option for this would be to serialize the data as JSON (either in the page, or by calling an action method via AJAX), and use it in the TreeView either at initialization time or after that:
var data = @Html.Raw(Json.Encode(ViewBag.Customers));
treeview.dataSource.data(data);
Alex Gyoshev
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
Thanks a lot for the quick answer. I will serialize the data.
Best regards,
Nby