handler null int binding validation

Hi, 

I need to cast an int value

from int to int?


Is possible?

Image_6529_1691599955832

I cannot modify my class and it is this:

Image_6890_1691599828429

and since its primitive value is "0", the textbos is already shown with a zero:

Image_8256_1691599852121

 I need it to be null so that it displays like this:

Image_2454_1691599915373



3 Replies

PK Priyanka Karthikeyan Syncfusion Team August 10, 2023 12:22 PM UTC

Hi Sergio Ayala,

To achieve your requirement, you can bind the TValue as int?. Please find the code snippet and sample for your reference.

<SfNumericTextBox TValue="int?" @bind-Value="@numericInstance.values">

</SfNumericTextBox>

@code {

    public class Numeric{

        public int? values {get; set;}

    }

 

    private Numeric numericInstance = new Numeric();

}

Sample: https://blazorplayground.syncfusion.com/rDVgZbMZTfgMyHIm

If this does not meet your requirement, please let us know. We are happy to assist you further.

Regards,

Priyanka K



SA Sergio Ayala replied to Priyanka Karthikeyan August 11, 2023 04:55 PM UTC

You have not understood me. I need something like that because I can't modify my class.


Image_5097_1691772875272


there is some way to cast?



PK Priyanka Karthikeyan Syncfusion Team August 25, 2023 03:16 PM UTC

Hi Sergio Ayala,

Thank you for bringing up this concern. Ensuring consistency between the class type and the TValue type is indeed crucial. We understand that the attempt to keep the class type as 'int' while binding the value as a nullable integer ('int?') can lead to unexpected issues.

If your aim is to establish a default value of null, We would like to propose the option of binding the value as 'int?' (nullable integer) inside the class. By doing so, you can effectively align the data types and appropriately set null as the default value for the binding.

Regards,

Priyanka K


Loader.
Up arrow icon