i have been using blazor and i encountered an issue could not find any soulution i have been trying to add text into input fields but its not updating
@page "/"
<PageTitle>Form</PageTitle>
<h1 style="text-align:center">Form & Validation</h1>
<EditForm Model="person" OnValidSubmit="FormSubmit" FormName="Form">
<DataAnnotationsValidator />
<label>Name :</label>
<InputText id="name" @bind-Value="person.Name" />
<br />
<br />
<button type="submit" class="btn btn-primary">submit</button>
</EditForm>
<p>New Name : @person.Name</p>
@code {
Person person = new Person();
string displaySuccess, styleColor;
private void FormSubmit()
{
displaySuccess = "Worked!";
styleColor = "Green";
}
class Person
{
public string? Name { get; set; }
}
}
I tried
{
if (person != null)
{
displaySuccess = "Worked!";
styleColor = "Green";
}
else
{
displaySuccess = "Wrong!";
styleColor = "red";
}
}
Then it always came up “Worked!” even though it was null what is happening ?
I tried looking up on google didnt find anything dunno why my value is not getting updated