Syncfusion SfDropDownList with UrlAdapter is always empty

150 Views Asked by At

I'm trying to use a Syncfusion Blazor SfDropDownList with the URL adapter to a custom (non web api) api hosted in the same project. The Dropdown list is returning "No results found" and the browser is correctly calling the URL and returning the payload according to the documentation.

How do I get the SfDropDownList to show data from a custom URL.

Payload returned from the browser network panel:

{
"result":[
  {"value":"sample 1","text":"sample 1"},
  {"value":"sample 2","text":"sample 2"}
],
"count":19
}

Blazor code:

<SfDropDownList TValue="string" TItem="ListItemStringOnly" PopupHeight="230px" Placeholder="Select a type" @bind-Value="EquipmentType">
    <SfDataManager Url="@Url" Adaptor="Adaptors.UrlAdaptor" CrossDomain=true Offline="true"></SfDataManager>
<DropDownListFieldSettings Text="Text" Value="Value"  />  <!-- tried lower case text and value as well -->
</SfDropDownList>

@code {
    string EquipmentType { get; set; }
    string Url;

    protected override async Task OnInitializedAsync()
    {
     Url = new EquipmentTypeLookup().ToReplyUrl();
   
    }
}

 public class ListItemStringOnly
    {
        public string Value { get; set; }
        public string Text { get; set; }

        public ListItemStringOnly(string val) {
            Value = val;
            Text = val;
        }
    }

Unformatted Dropdown:

empty dropdown

Documentation about the Url Adapter:

enter image description here

1

There are 1 best solutions below

0
On

You can pass the returned response with RequiresCounts attribute value as true or if the RequiresCounts attribute is not present on your returned response data then you can pass directly the response with datasource an array of objects as mentioned in the code:

var DataSource = [
{"value":"sample 1","text":"sample 1"},
{"value":"sample 2","text":"sample 2"}];

return dm.RequiresCounts ? new { result = DataSource, count = count } : DataSource;