I am hoping that someone can help me. I am trying to learn Blazor and I am creating an example site to create a shopping list. I am having issues updating the list items as I am unable to pass the items back from the Child Component to the parent component to then pass to the API call. From the update button I can hit the UpdateItem method but I am not sure how to pass the bound items from the three inputs.
<ListTemplate Loader="@GetShopping" ListGroupClass="orders-list">
<Loading>Loading...</Loading>
<Empty>Empty.......</Empty>
<Item Context="item">
<input @bind="item.Id" />
<input type="checkbox" @bind="item.IsDone" />
<input @bind="item.Item" />
<button @onclick="UpdateItem">Update</button>
</Item>
<AddNew>
<input placeholder="Something todo" @bind="newToDo" />
<button @onclick="AddTodo">Add Todo</button>
</AddNew>
</ListTemplate>
ListTemplate class @typeparam TItem
@if (items == null)
{
@Loading
}
else if (!items.Any())
{
@Empty
}
else
{
<div class="list-group @ListGroupClass">
@foreach (var item in items)
{
<div class="list-group-item">
@Item(item)
</div>
}
@AddNew
</div>}
@code
{
IEnumerable<TItem> items;
[Parameter] public Func<Task<IEnumerable<TItem>>> Loader { get; set; }
[Parameter] public RenderFragment Loading { get; set; }
[Parameter] public RenderFragment Empty { get; set; }
[Parameter] public RenderFragment AddNew { get; set; }
[Parameter] public RenderFragment<TItem> Item { get; set; }
[Parameter] public string ListGroupClass { get; set; }
protected override async Task OnParametersSetAsync()
{
items = await Loader();
}
}