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

Cannot get a stored value

2 Answers 61 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Dario
Top achievements
Rank 1
Veteran
Dario asked on 01 Oct 2020, 04:04 PM

I have this control

 

 

@(Html.Kendo().DropDownTreeFor(model=>model.NewCustomerCategoryCode)
                        .DataTextField("Name")
                        .DataValueField("id")
                        .AutoWidth(true)
                        .HtmlAttributes(new { style = "width: 100%" })
                        .DataSource(dataSource => dataSource
                            .Read(read => read
                                .Action("Read_DropDownTreeNewCustomerCategoriesData", "ListBox")
                            )
                        )
                        .Filter(FilterType.Contains)
                        .LoadOnDemand(true)
                    )

 

And this is the action

public JsonResult Read_DropDownTreeNewCustomerCategoriesData(string id)
        {
            var result = GetHierarchicalNewCustomerCategoryData()
                .Where(x => String.IsNullOrEmpty(id) ? x.ParentCode == null : x.ParentCode == id)
                .Select(item => new {
                    id = item.Code,
                    Name = item.Name,
                    hasChildren = item.HasChildren
                });
 
            return Json(result);
        }

 

I set correctly a value (and stored to database), but when I reopen a card it cannot get a value correctly.

When I try to debug into Action id parameter is not valued.

Why?

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 06 Oct 2020, 12:51 PM

Hello Dario,

Not sure what you mean by "reopen a card", but I see that your DropDownTree is configured to load items on demand:

.LoadOnDemand(true)

This means that child nodes are not loaded initially and will be loaded only after their parent is expanded. So in this scenario, if the value of "NewCustomerCategoryCode" matches the "id" of a node that is not yet loaded, the DropDownTree will have no selected node initially.

Consider removing the .LoadOnDemand option, so that all nodes are loaded initially. In this case if a node's "id" value is equal to the value of the "NewCustomerCategoryCode" field, this node will be selected in the DropDownTree.

As for the "id" parameter in the action, an id is passed only when a parent node is expanded. So for example, if my data contains 1 parent node and 10 child nodes, the action will be called twice: the first time the parent node will be loaded (no id will be sent with the request) and the second request will load the child nodes of the parent node (this time the id of the parent node will be available in the Action).

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Dario
Top achievements
Rank 1
Veteran
answered on 06 Oct 2020, 03:25 PM

Good work Ivan!

Thank you.

Tags
DropDownTree
Asked by
Dario
Top achievements
Rank 1
Veteran
Answers by
Ivan Danchev
Telerik team
Dario
Top achievements
Rank 1
Veteran
Share this question
or