Значение Inputselect не привязывается правильноC#

Место общения программистов C#
Ответить
Гость
 Значение Inputselect не привязывается правильно

Сообщение Гость »


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;
}
}
Tried to bind the id of the selected option in the input select to an integer but it is always set to 0. The categories are initialized properly and the segment itself when i create it is also initialized properly.


Источник: https://stackoverflow.com/questions/781 ... -correctly
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»