@binding-value in textbox throws a compiler error CS1503: Cannot convert from int to string

Using 

<SfTextBox Placeholder="Challenge Id" FloatLabelType="@FloatLabelType.Auto" Enabled="false" @bind-Value="@Challenge.Id"></SfTextBox>

throws an error for each field that is defined as an int

How can I fix this


3 Replies

KP Kokila Poovendran Syncfusion Team July 18, 2023 12:18 PM UTC

Hi Uwe Jädick,


We have validated the reported issue at our end and created the sample according to your needs. In TextBox component requires a string value for the "Value" property, and the @bind-Value attribute cannot be directly used with an integer property. 


We have prepared a sample that demonstrates this approach. Please try out the provided sample and let us know if you encounter any further issues or have any additional questions.


Code snippet:


<SfTextBox @bind-Value="@ValueSet" ></SfTextBox>

 

@code{

    public int Value { get; set; } = 10;

 

    public string ValueSet

    {

        get { return Value.ToString(); }

        set

        {

            if (int.TryParse(value, out int result))

            {

                Value = result;

            }

            else

            {

                Value = default;

            }

        }

    }

}



Regards,
Kokila Poovendran.

Attachment: BlazorTextBox_9d10183b.zip


UJ Uwe Jädick July 18, 2023 01:23 PM UTC

Thanks Kokila Poovendran,

That is the workaround I am using. I was in the impression that the fields could handle all data types as stated in the demo. The demo said the textboxes can handle string, integer and dates. Obviously that is not correct. That is why I created the post.

Best Regards
Uwe



KP Kokila Poovendran Syncfusion Team July 19, 2023 11:22 AM UTC

Hi Uwe Jädick,


We apologize for any confusion caused by the statement in our documentation mentioning support for int type. We are actively working on updating the TextBox documentation to provide clear examples and remove any ambiguity regarding the supported data types. We have given it the highest priority, and we aim to refresh the documentation section as soon as possible. We greatly appreciate your patience and understanding.


Regards,

Kokila Poovendran.


Loader.
Up arrow icon