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

ASP.NET MVC model binding

5 Answers 371 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andrii
Top achievements
Rank 1
Andrii asked on 29 May 2013, 03:26 PM
Hi! We want to use treeview with strongly-typed model binding (not AJAX). 
     
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));
           })
        )
We would like to add new node using this function. 
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);
       }
Is it way to bind and submit to server dynamically added treeview nodes with model?
Thanks!

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 30 May 2013, 06:39 AM
Hello Andrii,

The treeview will not post the newly inserted item to the controller automatically. You can probably use jQuery.ajax to make an ajax request to some action method which will insert the item in the database.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Andrii
Top achievements
Rank 1
answered on 30 May 2013, 06:42 AM
Thanks! But how to use treeview with classic asp.mvc model binding?
0
Atanas Korchev
Telerik team
answered on 30 May 2013, 07:11 AM
Hi Andrii,

 I do not understand your question. The Kendo TreeView won't automatically post the inserted item. You need to do that via code (e.g. making an ajax request using jQuery). Handling that request server side should also be done by you.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Andrii
Top achievements
Rank 1
answered on 30 May 2013, 07:59 AM
We have wizard on view, all data submits and binds via strongly typed data binding. We don't need ajax, we need to submit all controls including treeview data.

For example we creating Organization (name, address, etc.) and we adding into treeview departments, childs for them. And only after all this we submitting one time this form and save all this data (not AJAX form).
@using (Html.BeginForm(MVC.Organization.AddOrganization(),
          FormMethod.Post,
          new { enctype = "multipart/form-data" }))
{
     @Html.TextBoxFor(m => m.DisplayName, new { @class = "input-block-level", placeholder = "Display name" })
                 
     @(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));
            })
         )
        <input class="btn btn-large btn-primary" id="signinButton" type="submit" value="Add" />
}
[HttpPost]
        public virtual ActionResult AddOrganization(AddOrganizationModel model)
        {
            var response = OrganizationService.AddOrganization(new AddOrganizationRequest { Organization  = model });
           return RedirectToAction(MVC.Employee.Index());
        }
Does kendo treeview support strongly typed data binding?

0
Atanas Korchev
Telerik team
answered on 31 May 2013, 06:49 AM
Hi,

The Kendo TreeView is not an input element and its nodes are not sent as part of the form.

Regards,
Atanas Korchev
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
Andrii
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Andrii
Top achievements
Rank 1
Share this question
or