Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding Type double values in InputText of Blazor app Razor page

I am using InputText for almost all the attributes. Some of the attributes are of type Double. When I bind the double value in InputText its giving me error. How can i resolve this? I dont want to use InputNumber.

 <div class="form-group col">
 <label title="The quantity ">Quantity</label>
 <i class="fa fa-info-circle" style="color:dimgrey" title="The quantity"> 
 </i>
 <InputText @bind-Value="@trade.qty" class="form-control" />
 <ValidationMessage For="@(() => trade.qty)" />
 </div>

I am getting error at @trade.qty in <InputText @bind-Value="@trade.qty" class="form-control" /> as its a double value.

Model:

 public Double qty { get; set; }

I tried something like <InputText @bind-Value="@trade.qty.ToString()" class="form-control" /> It didnt't work.

like image 300
Shrey Avatar asked Feb 02 '26 03:02

Shrey


1 Answers

Use

<InputNumber @bind-Value=trade.qty min="1" max="999" />

It is bindable to double.

https://learn.microsoft.com/fr-fr/aspnet/core/blazor/forms-validation?view=aspnetcore-5.0