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

Bind drop down Json result

Hi,

I need create a drop down and bind datasource with datamanager that call an action that return a json.

But I can't bind this drop down

I attach an example. The last drop down (dropdown2) call getGames2 that return a json, but it is not binded




Attachment: DropDownLocalData_e3e2412c.zip

3 Replies

PO Prince Oliver Syncfusion Team November 14, 2018 12:04 PM UTC

Hi Manolo, 
 
Thanks for contacting Syncfusion support. 
 
We have checked the provided sample and were able to reproduce the reported issue in our end. Since JsonAdaptor cannot be used with Url, we suggest you to use UrlAdaptor  to fetch data from Controller method. Kindly refer to the following code snippet. 
 
[View] 
<script type="text/javascript"> 
  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: 'Game', value: 'Id' }, 
  });  
  listObj2.appendTo('#dropdown2'); 
</script> 
 
[Controller] 
public JsonResult getGames2() 
{ 
    var data = new DropdownlistGameList().DropdownlistGameLists(); 
    return Json(new { result = data }); 
} 
 
Regards, 
Prince 




MC Manolo Capdevila November 14, 2018 02:58 PM UTC

Hi,

I've change the example to your configuration. Method getGames is called, but the dorp down not show the data


Attachment: DropDownLocalData_b621036c.zip


CI Christopher Issac Sunder K Syncfusion Team November 15, 2018 12:37 PM UTC

Hi Manolo,  
 
Thanks for the update. 

We have validated the reported issue in our end. This issue occurs only on adding debugger to the controller method. As the component focus will be lost (blur) while making request, popup will not be opened on blur component. The sample will work fine when the debugger on controller is removed.  

If still you need to ensure this with debugger, you can set this.isActive and this.beforePopupopen as true as shown in the below code 

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: 'Game', value: 'Id' }, 
            
            actionComplete: function (args) { 
                this.isActive = true; 
                this.beforePopupOpen = true; 
             
            } 
        }); listObj2.appendTo('#dropdown2'); 

Please let us know if you have any other concerns. 

Thanks, 
Christo

Loader.
Live Chat Icon For mobile
Up arrow icon