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

[Solved] Binding and templating at the same time MVC2

2 Answers 70 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Noah
Top achievements
Rank 1
Noah asked on 20 Jul 2011, 12:09 AM
Hi there,

I was wondering if there was a way to both bind to a model AND specify a template for additional custom layout/content for each bound node in the TreeView control. Below is a sample of some code I am currently using. As it stands now, this code is just consuming data from an IEnumerable of my model object, where each object in the list is involved in a three tier hierarchy.

<% Html.Telerik().TreeView()
        .Name("TreeView")
        .BindTo(Model, mappings =>
        {
            mappings.For<TelerikFacLocUIDemo.Models.FacLocViewModel>(binding => binding
                    .ItemDataBound((item, category) =>
                    {
 
                        item.Text = category.Name;
                         
                    })
                    .Children(category => category.Children));
             
            mappings.For<TelerikFacLocUIDemo.Models.FacLocViewModel>(binding => binding
                    .ItemDataBound((item, product) =>
                    {
                        item.Text = product.Name;
                    }));
        })
        .Render();
%>

I've found an example of what I want to do in another post in this forum, however the view code posted by the Telerik rep was done with razor syntax... unfortunately, I'm stuck using the regular .aspx rendering engine for this project.

I am VERY new to both MVC, and Telerik UI extensions so any help/advice would be greatly appreciated. Thanks!

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 20 Jul 2011, 07:14 AM
Hello Noah,

 You can do so by using HTML for the Text property of the treeview item:


.ItemDataBound((item, category) =>
{
   item.Text = "<strong>" + category.Name "</strong>";
   item.Encoded = false; // to prevent the treeview from HTML encoding
})

All the best,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Noah
Top achievements
Rank 1
answered on 20 Jul 2011, 04:06 PM
Thanks, I'll give that a try!
Tags
TreeView
Asked by
Noah
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Noah
Top achievements
Rank 1
Share this question
or