I have bind my inputs to a model in my page and when I press the submit button to see the values at the object they are surrounded with single quotes for example:
Email: '[email protected]' , Password: '123'
Here is a code sample. Am I doing something wrong?
@page "/"
@using BlazorApp2.Classes;
<PageTitle>Test Page</PageTitle>
<input @bind-value="loginModel.Email" type="text"/>
<input @bind-value="loginModel.Password" type="password" />
<button @onclick="ExecuteLogin">Submit</button>
@code {
private LoginModel loginModel;
protected override Task OnInitializedAsync()
{
loginModel = new LoginModel();
return Task.CompletedTask;
}
public void ExecuteLogin()
{
}
}
CodePudding user response:
Your code seems to be all in order, this has to do with the way you display or use the values:
@page "/"
<PageTitle>Test Page</PageTitle>
<input @bind-value="loginModel.Email" type="text"/>
<input @bind-value="loginModel.Password" type="password" />
<button @onclick="ExecuteLogin">Submit</button>
<div>
"@loginModel.Email"
"@loginModel.Password"
</div>
@code {
class LoginModel
{
public string Email = "";
public string Password = "";
}
private LoginModel loginModel;
protected override Task OnInitializedAsync()
{
loginModel = new LoginModel();
return Task.CompletedTask;
}
public void ExecuteLogin()
{
}
}
See, there are no extra 's: https://blazorrepl.telerik.com/cwvwbsvH012HWMth43