I have a form on a blazor website that I am trying to define. The user selects how many textboxes to create. Based on that number, they are created. I need to then total the number typed into these textboxes.
I can create the desired number of text boxes, but where I'm struggling is dynamically binding a value to it so that I can create a function to total the numbers typed in. I've done some research, and see I can bind them to a collection.
This is what I'm trying... But it is not working, any help would be great.
<td>EE Only</td>
@{
for (int i = 0; i < AppData.PlanOption; i++)
{
<td>
<input @bind="eevalue.Vals" @bind:event="oninput" @onchange="() => IncrementEETotal()" />
</td>
}
}
<td style="background-color: rgb(192, 206, 219);"><input class="field" readonly @bind="eeTotal" /></td>
@code {
private void IncrementEETotal()
{
eeTotal = eevalue.Vals.Sum();
}
public class EEVals
{
public List<int> Vals { get; set; } = new List<int>();
}
public class EEItem
{
public int val { get; set; }
public string name { get; set; }
}
public EEVals eevalue { get; set; } = new EEVals();
}