Specifying a template when using BindTo

8 posts, 0 answers
  1. Adam
    Adam avatar
    24 posts
    Member since:
    Nov 2011

    Posted 29 Aug 2012 Link to this post

    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?
  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 30 Aug 2012 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Adam
    Adam avatar
    24 posts
    Member since:
    Nov 2011

    Posted 30 Aug 2012 Link to this post

    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.
  5. Nby
    Nby avatar
    5 posts
    Member since:
    Sep 2012

    Posted 21 Jan 2015 in reply to Alex Gyoshev Link to this post

    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.
  6. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 22 Jan 2015 Link to this post

    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.

     
  7. Nby
    Nby avatar
    5 posts
    Member since:
    Sep 2012

    Posted 22 Jan 2015 in reply to Alex Gyoshev Link to this post

    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.
  8. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 26 Jan 2015 Link to this post

    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.

     
  9. Nby
    Nby avatar
    5 posts
    Member since:
    Sep 2012

    Posted 28 Jan 2015 in reply to Alex Gyoshev Link to this post

    Hello Alex,

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

    Nby
Back to Top
UI for ASP.NET MVC is VS 2017 Ready