question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server-side blazor : <select> value is bound after being rendered

See original GitHub issue

When I want to display a select tag with its value bound to a property, the select is rendered with the value not bound (first item selected), the correct option is then selected immediately.

To reproduce, on the default Blazor template, I replaced the Counter.razor with this :

@page "/counter"

<select @bind="TestValue">
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
</select>

<input type="number" @bind="TestValue" />

@code {    
    int TestValue { get; set; } = 1;
}

When we go to this page and reload, we can briefly see the “0” before the “1” in the select. The input is bound immediately.

I don’t see this happens when navigating to the page, but it happens when I press F5 to reload the page.

I have this behavior in preview 7, I didn’t notice it in previous versions.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

0reactions
gulbananacommented, Oct 4, 2019

if anyone else found this issue searching for why their custom StateHasChanged-based binding wasn’t working - render your selection using option.selected now, not select.value!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor issue when binding to a select element
I am using @bind-value to bind the selected value of a select element to a variable in Blazor. It works fine, if I...
Read more >
ASP.NET Core Blazor performance best practices
If authoring a UI-only component that doesn't change after the initial render, regardless of parameter value changes.
Read more >
ASP.NET Core Blazor forms and input components
Data in the request that matches the name of the property is bound to the property. Inputs based on InputBase<TValue> generate form value...
Read more >
Getting Started with Dropdown List
The Blazor Dropdown List is a dynamic replacement of HTML select tags. It has a rich appearance and allows you to select a...
Read more >
Intro to Blazor Server Side - Includes SQL Data Access and ...
Blazor Server Side is an ASP.NET Core application type that uses SignalR to connect the client to the server. This allows for a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found