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

Id's not showing in markup after setting .TemplateId

1 Answer 48 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bartley
Top achievements
Rank 1
Bartley asked on 13 Nov 2013, 11:02 PM
In my Treeview I have the below line of code.   That works fine and shows both AlphaId and BravoId in the markup that I can access.

branch.Add().Text(childs.SomeTitle).Id(childs.AlphaId.ToString()).HtmlAttributes(new { data_foo = childs.BravoId });
But then When setting a:
.TemplateId("treeview-template")


That looks like this:

<script id="treeview-template" type="text/kendo-ui-template">
    #: item.text #    
    # if (!item.items) { #
        <a href="/A/B/#=item.id#"><img src="@Url.Content("~/Content/Images/Image.png")" /></a>
    # } #
</script>



I can no longer access foo it is showing null.

Why are the id's no longer showing or accessable?

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 15 Nov 2013, 02:49 PM
Hello,

When a client template is set, the treeview will serialize the data instead of render it on the server and so the attributes will be lost. The ID field should still be accessible in the data items but I am afraid that the only option that I can suggest to be able to access the foo value when using a client template is to load the data via Ajax. It should also be possible to render the same markup without using a client template by adding the HTML to the text and preventing the encoding e.g.

Html.Kendo().TreeView()
    .Name("treeview")
    .ItemAction(item =>
    {
        if (item.Items.Any())
        {
            item.Encoded = false;
            item.Text += "<a href='/A/B/" + item.Id + "'><img src='" + Url.Content("~/Content/Images/Image.png") + "' /></a>";
        }
    })


Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Bartley
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or