blazor

Two ways data binding - nothing happens


I am using .NET 8 and created a Blazor application (WebAssembly) and placed the following markup and code in Home.razor:

<input @bind="Title" />

<h2>Hello, @Title</h2>

@code {
    private string Title { get; set; } = string.Empty;
}

And I don't see any changes when I write something in the input, why?

enter image description here

My code is almost the same like here:

https://www.learnblazor.com/data-binding

and here:

https://www.pragimtech.com/blog/blazor/blazor-two-way-data-binding-example/

Here is the film: https://imgur.com/a/QqRKS3D

The solution: create Blazor STANDALONE application


Solution

  • The code is valid and works. You maybe want to make it bind oninput. Which will result in change when you type (not after leaving the input field as it is in your version.)

    <input @bind="Title" @bind:event="oninput" />
    

    Live version.

    If it still doesn't work you probably using SSR instead of wasm interactivity.