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

DropDownList TValue int error (Blazor 17.4.39)

After upgrading to blazor 17.4.39 DropDownList TValue int is giving following error.

DropDownList value is:@DropVal


EjsDropDownList Placeholder="e.g. Australia" TItem="Countries" TValue="int" Value="@DropVal" DataSource="@Country"
    DropDownListEvents TValue="int" ValueChange="onChange"
    DropDownListFieldSettings Value="Code"
/EjsDropDownList

@code {

    public int DropVal = 0;

    public class Countries
    {
        public string Name { get; set; }

        public int Code { get; set; }
    }

    List Country = new List
{
        new Countries() { Name = "Australia", Code = 1 },
        new Countries() { Name = "Bermuda", Code = 2 },
        new Countries() { Name = "Canada", Code = 3 },
        new Countries() { Name = "Cameroon", Code = 4 },
    };
    private void onChange(Syncfusion.EJ2.Blazor.DropDowns.ChangeEventArgs args)
    {
        DropVal = args.Value;
        StateHasChanged();
    }
}


blazor.server.js:15 [2019-12-21T06:09:13.615Z] Error: System.InvalidCastException: Null object cannot be converted to a value type.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType)
   at Syncfusion.EJ2.Blazor.BaseComponent.ChangeType(Object value, Type conversionType, Boolean isClientChange)
   at Syncfusion.EJ2.Blazor.DropDowns.EjsDropDownList`2.getItemData()
   at Syncfusion.EJ2.Blazor.DropDowns.EjsDropDownList`2.setValue()
   at Syncfusion.EJ2.Blazor.DropDowns.EjsDropDownList`2.updateValues()
   at Syncfusion.EJ2.Blazor.DropDowns.EjsDropDownList`2.initValue()
   at Syncfusion.EJ2.Blazor.DropDowns.EjsDropDownList`2.OnAfterRenderAsync(Boolean firstRender)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)





1 Reply

SD Saranya Dhayalan Syncfusion Team December 23, 2019 04:41 AM UTC

Hi Ashimaz, 
 
Thank you for contacting Syncfusion support 
 
 
We have checked your reported issue, you need to specify int nullable type to DropDownList TValue. Please find the below code snippet: 
 
@using Syncfusion.EJ2.Blazor.DropDowns 
 
 
DropDownList value is:@DropVal 
 
 
<EjsDropDownList Placeholder="e.g. Australia" TItem="Countries" TValue="int?" Value="@DropVal" DataSource="@Country"> 
    <DropDownListEvents TValue="int?" ValueChange="onChange"></DropDownListEvents> 
    <DropDownListFieldSettings Value="Code" Text="Name"></DropDownListFieldSettings> 
</EjsDropDownList> 
 
@code { 
 
    public int? DropVal = 0; 
 
    public class Countries 
    { 
        public string Name { get; set; } 
 
        public int Code { get; set; } 
    } 
 
    List<Countries> Country = new List<Countries> 
{ 
        new Countries() { Name = "Australia", Code = 1 }, 
        new Countries() { Name = "Bermuda", Code = 2 }, 
        new Countries() { Name = "Canada", Code = 3 }, 
        new Countries() { Name = "Cameroon", Code = 4 }, 
    }; 
    private void onChange(Syncfusion.EJ2.Blazor.DropDowns.ChangeEventArgs<int?> args) 
    { 
       DropVal = args.Value; 
        StateHasChanged(); 
    } 
} 
 
 
Could you please check the above code snippet and get back to us if you need further assistance on this? 
 
 
Regards, 
Saranya D 


Loader.
Live Chat Icon For mobile
Up arrow icon