Search code examples
c#async-awaitwebassemblyblazor-client-side

Blazor WebAssembly Navigation


I am trying to create CRUD using Blazor client side Preview (WebAssembly). I am calling CreateTodo() method on button click as given below.

<button type="submit" class="btn btn-success" @onclick="@(async () => await CreateTodo())">Create</button>

protected async Task CreateTodo(){
        await Http.SendJsonAsync(HttpMethod.Post, "https://localhost:44327/api/ToDoes", toDoItem);
        navigation.NavigateTo("/todos");
    }

In the above code

 navigation.NavigateTo("/todos");

The Object is submitted on server side but NavigateTo method is not called. Can anybody please guide me. I am new to this stuff.


Solution

  • Changing button type to type="button" instead of type="submit" solved my Problem. For more details you may visit https://github.com/dotnet/aspnetcore/issues/15564#issuecomment-460101825