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

Specifying a template when using BindTo

7 Answers 251 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 30 Aug 2012, 12:27 AM
Is it possible to specify a template when using BindTo? I tried the following:

@(
            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

Sort by
0
Alex Gyoshev
Telerik team
answered on 30 Aug 2012, 07:54 AM
Hello Adam,

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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Adam
Top achievements
Rank 1
answered on 30 Aug 2012, 05:15 PM
Ok, I hope this is a feature that will be added to a future version. It seems like a pretty basic feature. Otherwise server binding seems pretty pointless.
0
Nby
Top achievements
Rank 1
answered on 21 Jan 2015, 04:37 PM
Hi Alex,

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.
0
Alex Gyoshev
Telerik team
answered on 22 Jan 2015, 08:27 AM

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.

 
0
Nby
Top achievements
Rank 1
answered on 22 Jan 2015, 10:54 AM
Hello Alex,

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.
0
Alex Gyoshev
Telerik team
answered on 26 Jan 2015, 09:27 AM

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);

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.

 
0
Nby
Top achievements
Rank 1
answered on 28 Jan 2015, 12:57 PM
Hello Alex,

Thanks a lot for the quick answer. I will serialize the data.
Best regards,

Nby
Tags
TreeView
Asked by
Adam
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Adam
Top achievements
Rank 1
Nby
Top achievements
Rank 1
Share this question
or