I am using SyncFusion.Blazor v18.1.0.43
I am trying to populate a DropDownList with remote data from my ODataV4 API. When I run the program, I am getting the following in Chrome Dev Tools
blazor.server.js:15 [2020-04-16T20:04:39.790Z] Error: System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.BaseComponent.ChangeType(Object value, Type conversionType, Boolean isClientChange)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<>c__DisplayClass437_0.<getDataByValue>b__0(TItem fields)
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.getDataByValue(TValue value)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.updateValues(Dictionary`2 props)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.initValue(Dictionary`2 props)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.InitialRendered()
at Syncfusion.Blazor.BaseComponent.InitComponent()
at Syncfusion.Blazor.BaseComponent.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.DropDownBase`1.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.OnHybridAfterRender(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Here is my .razor page code for the DropDownList;
<SfDropDownList id="accountOwner" CssClass="adjust-sf-padding" TValue="Guid" TItem="Account" @bind-Value="@ManageAccountType.OwnerId" Query="@OwnerIdQuery">
<SfDataManager Headers="@HeaderData" Url="@CdApiAccountsUrl" Adaptor="Adaptors.ODataV4Adaptor" CrossDomain=true></SfDataManager>
<DropDownListFieldSettings Text="AccountName" Value="ID"></DropDownListFieldSettings>
</SfDropDownList>
Here is my OwnerIdQuery in the .razor.cs file;
protected Query OwnerIdQuery = new Query().Select(new List<string> { "Id", "AccountName" });
Here is my ManageAccountType definition in the .razor.cs file;
protected AccountTypeModel ManageAccountType { get; set; } = new AccountTypeModel();
Here is my AccountTypeModel Class;
public class AccountTypeModel where I am trying to bind the OwnerId property.
{
public string AccountType { get; set; }
public Guid OwnerId { get; set; } = Guid.Empty;
public Guid SalesPersonId { get; set; } = Guid.Empty;
public string Status { get; set; }
public bool IsTaxExempt { get; set; }
}
And her is my Account class that is references as the TItem, which is what is returned from the API call;
public class Account
{
public Guid Id { get; set; } = Guid.Empty;
public string AccountName { get; set; }
public string AccountType { get; set; }
public Guid OwnerId { get; set; } = Guid.Empty;
public string OwnerName { get; set; }
public string PhoneNumber { get; set; }
public string Fax { get; set; }
public string PrimaryAddressLine { get; set; }
public string SecondaryAddressLine { get; set; }
public string City { get; set; }
public string StateProvinceCode { get; set; }
public string PostalCode { get; set; }
public string CountryRegionCode { get; set; }
public Guid SalesPersonId { get; set; } = Guid.Empty;
public Guid MailJobProxyId { get; set; } = Guid.Empty;
public string PostagePaymentMethodType { get; set; }
public string AccountNumber { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string MailerId { get; set; }
public bool IsTaxExempt { get; set; }
public string Status { get; set; }
public bool DeleteFlag { get; set; }
}
Does the DropDownList support a TValue of type Guid?
I am not sure how to troubleshoot this issue on my end. I get results back from the API when using Postman at the specified URL endpoint using the query https://{{url}}/v1/accounts?$select=Id,AccountName
{
"@odata.context": "https://localhost:44371/v1/$metadata#Accounts(Id,AccountName)",
"value": [
{
"Id": "11d73913-8e87-4cd8-0e4a-08d7d29816ae",
"AccountName": "Test Company 38"
},
{
"Id": "49cf42e5-209f-4f43-0e49-08d7d29816ae",
"AccountName": "Test Customer 37"
},
{
"Id": "60c37c91-ad75-41c3-0e43-08d7d29816ae",
"AccountName": "Test Customer 32"
}
]
}
I have another DropDownList component on another page that is using a similar approach and is hitting the same API, just a different endpoint. That component populates correctly and does not get the nul referenc error, but it has a TValue="string" instead of TValue="Guid"
Is there any other information you need?