Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

StateHasChanged is not re rendering component

$
0
0

I am using blazor server side for one of my project , petty new to me . I am stuck at very first screen, the login screen.

Below is my razor component html

<div class="row vh-100 align-items-center justify-content-center"><div class="col-sm-8 col-md-6 col-lg-4 bg-white rounded p-4 shadow"><div class="row justify-content-center mb-4"><img src="Images/AQuity.png" class="w-50 h-50" /></div><form><div class="mb-4"><label for="email" style="text-align:left" class="form-label label-left w-100">Email Address</label><input type="email" class="form-control form-control-sm" id="email" @bind=@_credential.Email /></div><div class="mb-4"><label for="password" style="text-align:left" class="form-label label-left w-100">Password</label><input type="password" class="form-control form-control-sm" id="password" @bind=@_credential.Password /></div><button class="btn btn-warning btn-sm w-100" @onclick=Authenticate>Login</button></form><p class="mb-0 mt-2 text-center">Forgot Password? <a href="#" class="text-decoration-none">Reset Now!</a></p>    @if (!_result.Success)    {<p class="text-danger">@msg</p>    }</div>

my code behind partial class

    public partial class Login {     [Inject]     protected IAuthenticateService _authenticateService { get; set; }     [Inject]     protected NavigationManager Navigation { get; set; } = default!;     private Credential _credential { get; set; } = new Credential();     private ResultSet _result { get; set; } = new ResultSet();     public string msg = string.Empty;     private void Authenticate()     {         _result = _authenticateService.Authenticate(_credential);         if (_result.Success)         {             Navigation.NavigateTo("");         }         else         {             msg = "new error !";             this.StateHasChanged();         }     } }

On below method

    private void Authenticate(){    _result = _authenticateService.Authenticate(_credential);    if (_result.Success)    {        Navigation.NavigateTo("");    }    else    {        msg = "new error !";        this.StateHasChanged();    }}

in else block if _result.Success is false it will contain a error message in msg field

and that is set to display on html part as

    @if (!_result.Success){<p class="text-danger">@msg</p>}

But even after calling this.StateHasChanged(); , that component is not re rendering.How to achieve this in blazor ? on failed login to show msg on component

This is server side blazor on .net 8.0


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>