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

[Solved] Actions for custom binding

1 Answer 61 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.
OldusRein
Top achievements
Rank 1
OldusRein asked on 15 Sep 2010, 07:25 PM
Hello,
I have seen in the documentation that I can add an action for a item in a treeview like this:

<%= Html.Telerik().TreeView()
            .Name("TreeView2")
            .Items(item =>
            {
                item.Add()
                    .Text("User Informationen")
                    .ImageUrl("~/Content/TreeView/FirstLook/contacts.gif")
                    .ImageHtmlAttributes(new { alt = "User" })
                    .Action("Index", "Home");
                    ;
  
                      
            })

Now I have a custom binding for my Treeview that looks like:
<%= Html.Telerik().TreeView()
            .Name("TreeView")
                         .BindTo(ViewData["TreeViewEntries"] as List<TreeViewItem>, mappings =>
                                {
                                    mappings.For<TreeViewItem>(binding => binding
                                                                              .ItemDataBound((item, treeViewItem) =>
                                                                                                 {
                                                                                                     item.Text = treeViewItem.Text;
                                                                                                     item.Value = treeViewItem.Value;
                                                                                                     item.Url = treeViewItem.Url;
                                                                                                     })
                                                                              .Children(treeViewItem => treeViewItem.Items));
                                     
                                })
     %>

How can I apply for every single item a action that is fired when the users clicks the element?

Thank you

1 Answer, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 16 Sep 2010, 02:13 PM
Hi OldusRein,

In the first case we have NavigationItemBuilder which has Action method.

In your case we have ItemDataBound which has NavigationItem with ControllerName and ActionName properties.
Here is solution:
<%= Html.Telerik().TreeView()
            .Name("TreeView")
            .BindTo(ViewData["TreeViewEntries"] as List<TreeViewItem>, mappings =>
            {
                mappings.For<TreeViewItem>(binding => binding
            .ItemDataBound((item, treeViewItem) =>
                            {
                                item.Text = treeViewItem.Text;
                                item.Value = treeViewItem.Value;
                                item.ActionName = "Index";
                                item.ControllerName = "Home";
                                })
            .Children(treeViewItem => treeViewItem.Items));
            })
%>


Best wishes,
Hristo Germanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
OldusRein
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
Share this question
or