Q:

How do you bind the value of the HTML element with a C# property in Blazor?

0

This code will help you to understand how to bind the value of the HTML element with a C# property in Blazor.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

You have to use the bind attribute to reflect the DOM element value in the C# property.

<p>
    @* This is the input element *@
    Enter your name: <input type="text" @bind=@name />

    <button @onclick="@PrintName">Print Name</button>
</p>
@code {
    string name;

    private void PrintName()
    {
      Console.WriteLine(name); // Here the entered name will be printed.
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now