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

Binding a Toolbar to data

1 Answer 138 Views
Toolbar
This is a migrated thread and some comments may be shown as answers.
Dominic
Top achievements
Rank 1
Dominic asked on 10 May 2018, 03:46 PM

Is there a way of binding a Toolbar to data in the same way as the Treeview can be bound to data?

I have tried creating my toolbar list dynamically as follows.

List<ToolBarItem> toolbaritems = new List<ToolBarItem>();
ToolBarItem item = new ToolBarItem
{
    Text = "Button",
    Type = CommandType.Button
};
toolbaritems.Add(item);
ToolBarItemFactory factory = new ToolBarItemFactory(toolbaritems);
ViewData["DocumentToolbar"] = factory;

I have then tried to bind the data to the control as follows.

@(Html.Kendo().ToolBar()
    .Name("ToolBar")
    .Items((Action<ToolBarItemFactory>) ViewData["DocumentToolbar"]))

I am getting the following error.

InvalidCastException: Unable to cast object of type 'Kendo.Mvc.UI.Fluent.ToolBarItemFactory' to type 'System.Action`1[Kendo.Mvc.UI.Fluent.ToolBarItemFactory]'.

Is this possible? And if so, how?

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 15 May 2018, 10:33 AM
Hello Dominic,

The facility you are refering to is the BindTo mechanism (https://demos.telerik.com/aspnet-mvc/treeview/local-data-binding). Such is not available for the ToolBar. However, you can add a loop in the Items() method as action, traverse the object from the ViewData and bind it using the ToolBarItemFactory's methods. Similar to this demo here (https://demos.telerik.com/aspnet-mvc/menu/menu-bind-attributes), but using the Toolbar instead. 

Regards,
Ianko
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Toolbar
Asked by
Dominic
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or