I'm implementing a simple pin-up board with Blazor WebAssembly. When removing any card with the X button, it's always the last element from the list that's removed.
@foreach (var item in _cards)
{
<div class="card-title">
<input type="text" id="@item.TitleElementId" value="@item.Title" />
<button class="btn-remove" @onclick="() => RemoveCard(item)">X</button>
</div>
}
<button class="btn-add" @onclick="AddNewCard">+</button>
@code {
private List<Card> _cards = new List<Card>();
private void AddNewCard()
{
_cards.Add(new Card());
}
private void RemoveCard(Card card)
{
_cards.Remove(card);
// Also tried _cards.RemoveAll(i => i.TitleElementId == card.TitleElementId);
}
}