DropDownTree input field does not bind selected items

1 Answer 115 Views
DropDownTree
n/a
Top achievements
Rank 1
Iron
n/a asked on 14 Feb 2023, 03:45 PM | edited on 15 Feb 2023, 07:20 AM

 

Good morning,
I have a problem with model binding
The component loads the data correctly but if I select multiple values ​​it binds me to only one value in "TipologiaFormato" present in the model.
"TipologiaFormato" is a string

What type of field must it be to bind all selected data?
Thank you

 

Code:

<form-item field="TipologiaFormato" col-span="1">
                            <item-label text="Tipologia Formato:" optional="false" />
                            <dropdowntree-editor auto-close="false" dataspritecssclassfield="spriteCssClass" value-template-id="dropdowntree-value-template" template-id="dropdowntree-template" name="dropdowntree" style="width: 100%">
                                <hierarchical-datasource>
                                    <schema>
                                        <hierarchical-model id="id"></hierarchical-model>
                                    </schema>
                                    <transport>
                                        <read url="@Url.Action("Items_GetAction", "Controller")" />
                                    </transport>
                                </hierarchical-datasource>
                                <checkboxes check-children="true" enabled="true" />
                            </dropdowntree-editor>
                        </form-item>

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 17 Feb 2023, 02:25 PM

Hello Giorgio,

I would recommend setting the data type of the Model property "TipologiaFormato" to a List<string>:

public List<string> TipologiaFormato { get; set; }

The Model property "TipologiaFormato" will be submitted through the form data as per the following screenshot:

As a result, you can intercept the submitted values on the server:

I am attaching a runnable sample for your reference.

 

 

Regards, Mihaela 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/.

n/a
Top achievements
Rank 1
Iron
commented on 22 Feb 2023, 03:40 PM

Hi Michaela,
With your instructions it works now.
I still have a problem, when "TipologiaFormato" comes to me compiled from the model I get this error:
"System.NullReferenceException: 'Object reference not set to an instance of an object.'
"
I think it's because the control hasn't loaded the datasource yet
How can I fix it?

Mihaela
Telerik team
commented on 27 Feb 2023, 08:44 AM

Hi Giorgio,

Thank you for your reply.

According to the shared screenshot, the DropDownTree editor has two "name" attributes ("Destinatari" and "dropdowntree"). Would you please set the "name" attribute with an unique value (for example, "dropdowntree_Destinatari")?

Here you can review the configuration of the editor for Model property "TipologiaFormato" :

            <form-item field="TipologiaFormato" col-span="1">
                <item-label text="Tipologia Formato:" optional="false" />
                <dropdowntree-editor auto-close="false"
                   name="dropdowntree_TipologiaFormato"
                   check-all="true"
                    dataspritecssclassfield="spriteCssClass"
                    datatextfield="text"
                    style="width: 100%">
                    <hierarchical-datasource>
                        <schema>
                            <hierarchical-model id="id"></hierarchical-model>
                        </schema>
                        <transport>
                            <read url="@Url.Action("GetData", "Home")" />
                        </transport>
                    </hierarchical-datasource>
                    <checkboxes check-children="true" enabled="true" />
                </dropdowntree-editor>
            </form-item>

Also, I have updated the previously shared demo for your reference - the "TipologiaFormato" values are bound successfully to the DropDownTree that is integrated in a form. Would you please review the attached runnable sample (.NET 6 application, Telerik UI for ASP.NET Core 2022.3.913) and let me know if it applies to your scenario?

n/a
Top achievements
Rank 1
Iron
commented on 02 Mar 2023, 09:43 AM

Good morning,
unfortunately it doesn't work yet.
I replied as in the example

When I load the page it doesn't display the default "Postcards" but it is always empty

What can it be? Could it be that it hasn't done data binding yet, or is it not needed?

 

 

n/a
Top achievements
Rank 1
Iron
commented on 06 Mar 2023, 09:15 AM

Thank you
I solved the problem.
It was due to a version difference between the installed dll and the CDNs (https://cdn.kendostatic.com)
Mihaela
Telerik team
commented on 06 Mar 2023, 01:28 PM

Thank you for the update, Giorgio.

Indeed, it is important to ensure that the version of the Kendo.MVC.dll file and the client-side resources (scripts and styles) is the same.

Tags
DropDownTree
Asked by
n/a
Top achievements
Rank 1
Iron
Answers by
Mihaela
Telerik team
Share this question
or