I am trying to bind selected category id to the option the user selects but the id always defaults to 0 no matter what i select.
Код: Выделить всё
Name
Description
Category:
@foreach (var category in Categories)
{
@category.Name
}
@code {
[SupplyParameterFromForm]
public SegmentModel segment { get; set; } = new();
public int SelectedCategoryId { get; set; }
[Parameter]
public List Categories { get; set; } = new();
protected override async Task OnInitializedAsync()
{
Categories = await manager._categoryRepository.GetAllCategoriesAsync();
}
private async Task HandleSubmit()
{
// await manager._categoryRepository.AddCategoryAsync(Category);
segment.CategoryId = SelectedCategoryId;
await manager._segmentRepository.AddSegmentAsync(segment);
}
private void HandleCategorySelection(ChangeEventArgs args)
{
// Parse the selected value from the event args
int selectedId = Convert.ToInt32(args.Value);
// Set the SelectedCategoryId
SelectedCategoryId = selectedId;
}
}
Источник: https://stackoverflow.com/questions/781 ... -correctly