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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DropDownList TValue int error (Blazor 17.4.39)

Thread ID:

Created:

Updated:

Platform:

Replies:

150121 Dec 21,2019 06:14 AM UTC Dec 23,2019 04:41 AM UTC Blazor 1
loading
Tags: Dropdown List
ashimaz
Asked On December 21, 2019 06:27 AM UTC

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)





Saranya Dhayalan [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon