Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had develop the login application. when I sign I had consumed the api but page completely reload after click the sign button. I don't want reload just execute the logic only. This is the blazor web assembly application.
HTML
<main class="form-signin">
  <form>    
    <img class="mb-4" src="/MainLogo.png" alt="" width="72" height="57">
    <h1 class="h3 mb-3 fw-normal">Please sign in</h1>

    <div class="form-floating">
      <input type="email" class="form-control" id="floatingInput" @bind="username" placeholder="name@example.com">
      <label for="floatingInput">Email address</label>
    </div>
    <div class="form-floating">
      <input type="password" class="form-control" id="floatingPassword" @bind="password" placeholder="Password">
      <label for="floatingPassword">Password</label>
    </div>

    <div class="checkbox mb-3">
      <label>
        <input type="checkbox" value="remember-me"> Remember me
      </label>
    </div>
    <button class="w-100 btn btn-lg btn-primary"  @onclick="sign">Sign in</button>
    <p class="mt-5 mb-3 text-muted">© 2017–2021</p>
  </form>
</main>




C#
protected async void sign()
    {
        Dictionary<string, string> keyvalues = new Dictionary<string, string>();
        keyvalues.Add("userName", username);
        keyvalues.Add("password", password);

        var client = ClientFactory.CreateClient("WebAPI");

        var request = new HttpRequestMessage(HttpMethod.Post,"api/Account/Login");

        var content = JsonConvert.SerializeObject(keyvalues);

        StringContent stringContent = new StringContent(content, System.Text.Encoding.UTF8,"application/json");

        HttpResponseMessage response = await client.PostAsync(request.RequestUri, stringContent);


    }


What I have tried:

I had develop the login application. when I sign I had consumed the api but page completely reload after click the sign button. I don't want reload just execute the logic only.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900