Bind json data

Hello,

I am trying to bind the json data to dropdownlist but its not working.

Below is my controller action code.

public JsonResult getGames2()
        {
            var data = new DropdownlistGameList().DropdownlistGameLists();

            IEnumerable<object> dropdownFilteredData=data.Select(s => new
            {
                key = s.Game,
                value = s.Id
            });
            return Json(new { result = dropdownFilteredData });
            //return Json(new { result = data, count = data.Count });
        }

And javascript code is

        var listObj2 = new ej.dropdowns.DropDownList({
            placeholder: 'Select a game',
            dataSource: new ej.data.DataManager(
                {
                    url: "@Url.Action("getGames2", "Dropdownlist")",
                    adaptor: new ej.data.UrlAdaptor(),
                    crossDomain: true
                }),
        }); listObj2.appendTo('#dropdown2');

but its not working.I have also attached sample code.Just click on DropdownList hyperlink and select Remote Data2.

Attachment: DropDownLocalData_3cceb706.zip

4 Replies 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team May 13, 2021 04:54 PM UTC

Hi Prashant 

Thanks for contacting Syncfusion support. 

We are checking the reported query in our end. We will update further details in 2 business days (May 18, 2021). We appreciate your patience until then. 

Regards, 
Ponmani M 



PM Ponmani Murugaiyan Syncfusion Team May 18, 2021 03:45 PM UTC

Hi Prashant, 

Thanks for the patience. 

We have checked the shared sample and you have missed to bind the fields for the DropDownList component. So, we suggest you to define the fields based on the retuned data from the URL data source to get rid of the reported issue. 

            var listObj2 = new ej.dropdowns.DropDownList({ 
            placeholder: 'Select a game', 
            dataSource: new ej.data.DataManager( 
                { 
                    url: "@Url.Action("getGames2", "Dropdownlist")", 
                    adaptor: new ej.data.UrlAdaptor(), 
                    crossDomain: true 
                }), 
            fields: { text: 'key', value: 'value' }, 
        }); listObj2.appendTo('#dropdown2'); 

Screenshot

 

 

 
Regards, 
Ponmani M. 


Marked as answer

PP Prashant Prasad May 19, 2021 12:26 PM UTC

Hi Ponmani

Thanks for the reply.

Will try and let you know if have any issue.


PM Ponmani Murugaiyan Syncfusion Team May 20, 2021 04:21 AM UTC

Hi Prashant, 

Welcome. Please get back us if you need further assistance. 

Regards, 
Ponmani M 


Loader.
Up arrow icon