bind value

asghar bizaval 0 Reputation points
2025-02-05T08:27:42.0666667+00:00

Hello .I just started Blazor.

Why don't the above values ​​change when I change the input?

For example, no matter how much I change the tel in the input, it doesn't change in the label.

I used both @bind-value and @bind.

I still don't get an answer.

@page "/customer"

<h3>name : @customerModel.name</h3>
<input @bind="@customerModel.name" />

<h3>tel : @customerModel.tel</h3>
<input @bind-value="@customerModel.tel"  type="number"/>


@code {
    customerModel customerModel = new()
        {
            id = 10,
            name = "ali",
            tel = 1122221
        };
}

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,665 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ruikai Feng - MSFT 2,756 Reputation points Microsoft Vendor
    2025-02-05T09:16:34.46+00:00

    Hi,@asghar bizaval ,there's nothing wrong with your codes ,make sure your component is in interactive render mode

    You could call @rendermode InteractiveServer in your component to apply InteractiveServer render mode to current component,you could also call

    <Routes @rendermode="InteractiveServer" />
    .......
    <HeadOutlet @rendermode="InteractiveServer" />
    

    in app.razor to configure the whole app as interactive.

    Now it's ok on my side :

    User's image

    For more details,you could read this document


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Ruikai Feng

    1 person found this answer helpful.
    0 comments No comments

  2. Bruce (SqlWork.com) 71,686 Reputation points
    2025-02-05T17:42:18.2333333+00:00

    for Blazor components the default render mode is static with no event processing. that means @bind-value only handles one-way binding (the initial component render). You need to specify the render mode for any events to process and support two-way binding.

    you can specify for each component, or change the default for the application. see docs:

    https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.