Blazor

How can you read the current value of an input element in Blazor?

How can you read the current value of an input element in Blazor?

The value of an input element is updated in the wrapper with the change events of elements in Blazor. To get the current value for each character input, you must use the oninput event of the input element. This can be achieved by binding the oninput event (native event) using the @bind:event=“oninput“.

 @CurrentValue
 <input type="text" @bind="@CurrentValue" @oninput="@((e) => { CurrentValue=(string)e.Value;})" />
  
 @code {
     private string CurrentValue {get;set;} = "blazor";
 } 

I would suggest you check the below link for better understanding:
https://stackoverflow.com/questions/52651771/how-can-you-read-the-current-value-of-an-input-in-an-onkeypress-method-in-blazor

Sumitra Kumari Shaw

An Engineering graduate who Enjoys building things that live on the internet.