We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Binding to Dictionary

Is it possible to bind a ejs-dropdownlist to a dictionary object from a linq query?

Dictionary<string, Guid> vEmps = res.Emps.ToDictionary(g => g.Badge, g => g.EmpId);
<ejs-dropdownlist id="ddlvEmps" dataSource="@Model.vEmps" popupHeight="220px">
    <e-dropdownlist-fields text="Key" value="Value"></e-dropdownlist-fields>
The data does get bound to the control, but looks like not in the proper format.


1 Reply

PO Prince Oliver Syncfusion Team March 12, 2019 10:12 AM UTC

Hi Michael, 
Thank you for contacting Syncfusion support.  
We have checked shared code snippet and screen shot. In your code snippet DropDownList component’s field property is mapped to “key” and “value for text and value fields respectively, but your json data source from the controller does not match this specified key and value pair data in the json object. So, the DropDownList’ s items list is not generated.  
<ejs-dropdownlist id="ddlvEmps" dataSource="@Model.vEmps" popupHeight="220px"> 
    <e-dropdownlist-fields text="Key" value="Value"></e-dropdownlist-fields> 
The data source must be in following format to work properly with the DropDownList control. Kindly make necessary changes in your end. 
dataSource: [ 
    { "Key": "779A", "Value": "00000000-0000-0000-0000-000000000000" }, 
    { "Key": "201A", "Value": "5602d953-563e-48e3-aaf3-0020ee4434be" } 
Please let us know if you need any further assistance on this. 

Live Chat Icon For mobile
Up arrow icon