Hi! We want to use treeview with strongly-typed model binding (not AJAX).
This is our TreeView:
We would like to add new node using this function.
Is it way to bind and submit to server dynamically added treeview nodes with model?
Thanks!
This is our TreeView:
@(Html.Kendo().TreeView().Name("treeviewDepartments")
.BindTo(Model.Departments, (NavigationBindingFactory<
TreeViewItem
> mappings) =>
{
mappings.For<
AddDepartmentTreeModel
>(binding => binding.ItemDataBound((item, dapartment) =>
{
item.Text = dapartment.Name;
})
.Children(department => department.Departments));
})
)
function addDepartment()
{
var treeView = $("#treeviewDepartments").data("kendoTreeView");
var selectedNode = treeView.select();
// passing a falsy value as the second append() parameter
// will append the new node to the root group
if (selectedNode.length == 0) {
selectedNode = null;
}
treeView.append({
text: "New department"
}, selectedNode);
}
Thanks!