I have created a login component with a RadzenTemplateForm
that posts to an account controller that takes a LoginViewModel
:
namespace EFS.Presentation.Blazor.Models
{
public class LoginViewModel
{
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
}
This is the form from the Login component:
<RadzenTemplateForm Data=@Model Action="/Account/Login" Method="post" TItem="EFS.Presentation.Blazor.Models.LoginViewModel">
<ChildContent>
<div class="row">
<div class="col-md-3">
<RadzenLabel Component="Email" style="vertical-align: sub" Text="Email:"/>
</div>
<div class="col-md-9">
<RadzenTextBox style="width: 100%" @bind-Value="@Model.Email" Name="Email"/>
</div>
</div>
<div style="padding-bottom: 4px; padding-top: 4px" class="row">
<div class="col-md-3">
<RadzenLabel Component="Password" style="vertical-align: sub" Text="Password:"/>
</div>
<div class="col-md-9">
<RadzenPassword style="width: 100%" @bind-Value="@Model.Password" Name="Password"/>
</div>
</div>
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-9">
<RadzenCheckBox TriState="false" @bind-Value="@Model.RememberMe" TValue="bool" Name="RememberMeCheckBox" />
<RadzenLabel Component="RememberMeCheckBox" style="margin-left: 5px" Text="Keep me logged in"/>
</div>
</div>
<div class="row">
<div class="col-md-3">
</div>
<div class="d-flex col-md-9 justify-content-between" style="text-align: left">
<RadzenLink Text="Reset Password"/>
<RadzenButton ButtonType="ButtonType.Submit" Size="ButtonSize.Small" style="width: 125px" Text="Login" />
</div>
</div>
</ChildContent>
</RadzenTemplateForm>
Here is the code I use with Serilog to test the parameters received by the account controller:
[HttpPost]
public async Task<IActionResult> Login(LoginViewModel model)
{
Log.Information("Model: {@model}", model);
}
No matter whether the "remember me" checkbox is checked on the Login component, the value passed to the account controller for RememberMe
is always false using this code. If, however, I add a Click
event to the submit button and post the LoginViewModel
via JSON then the correct RememberMe
value is logged. I am using Radzen.Blazor 3.11.6. Please let me know what I may be doing wrong here.