Home > OS >  After using <InputSelect> first value in select is empty
After using <InputSelect> first value in select is empty

Time:11-16

I have been working for a while with Blazor Server host model and now i am building forum with it. I have small strange case, maybe someone will help me to find solution.

This is EditForm

<EditForm Model="@Category">
    <InputSelect id="category"  @bind-Value="@Category.Id">
           
            @foreach (var category in Categories!)
                {
                    <option value="@category.Id">@category.Category</option>
                }
    </InputSelect>
</EditForm>

This is list of items:

Categories = await _repository!.GetAllCategories();

This is how "GetAllCategories()" looks like:

        public async Task<IEnumerable<CategoryEntity>> GetAllCategories()
    {
       return await _context.Categories.OrderBy(x=>x.Id).ToListAsync();
    }

and the thing is:

First item in Select is blank: enter image description here

How can i make first item as Value of it? Has someone found something similar?

CodePudding user response:

I found solution.

I changed:

 <InputSelect id="category"  @bind-Value="@Category.Id">

to:

 <InputSelect id="category"  @bind-Value="@Category.Category">
  • Related