@page "/"
<div class="container border">
<h3>Users</h3>
<hr />
<button @onclick="AddValue" class="btn btn-primary">Add User</button>
@for (int i = 0; i < values.Count; i++)
{
int index = i;
<div>
<input type="text" @onchange="(e) => UpdateValue(index, e.Value.ToString())" value="@values[i]" class="form-control" />
<button @onclick="() => RemoveValue(index)" class="btn btn-outline-danger">Remove</button>
</div>
}
<hr />
<div>
<button @onclick="HandleSubmit" class="btn btn-success">Submit</button>
</div>
<hr />
@for (int j = 0; j < values.Count; j++)
{
<p>@values[j]</p>
}
</div>
@code {
private List<string> values = new List<string>();
private void AddValue() => values.Add("");
private void UpdateValue(int i, string value) => values[i] = value;
private void RemoveValue(int i) => values.RemoveAt(i);
private void HandleSubmit()
{
//Access and validate the values list here
}
}