Skip to content

[Blazor] Select tag is not bound on first render #6550

Closed
@sebastienros

Description

@sebastienros

In the following example, the initial value of currentServer is not bound to the select tag.
And if I specify select="selected" in one option, then it's not reflected in the variable.
It works when I change the variable by code, or when the selection is changed.

Sample:

<p>Current server: @currentServer</p>

<div class="form-group">

    <select class="form-control" bind="@currentServer">
        <option value="WindowsPhysical">Windows - Physical</option>
        <option value="LinuxPhysical">Linux - Physical</option>
        <option value="WindowsCloud">Windows - Cloud</option>
        <option value="LinuxCloud">Linux - Cloud</option>
    </select>

</div>

<button class="btn btn-primary" onclick="@RunJob">Run</button>

@functions {
    string currentServer = "LinuxCloud";

    void RunJob()
    {
        currentServer = "WindowsCloud";
    }
}

Metadata

Metadata

Assignees

Labels

✔️ Resolution: DuplicateResolved as a duplicate of another issuearea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions