Razor Component Return Html but not Data from api call until page refresh manually

Prathamesh Shende 511 Reputation points
2025-07-29T05:12:07.5666667+00:00

Hello There,

blazor Web App .net 8 Interactive Render Mode Auto.

sometimes, page load in razor in blazor wasm side the html content appears correctly but api doesnt get called and data not get loaded but I can see in command prompt window ef core queries have ran (must be pre-rendered on server).

if I visit another page still everything is loaded but not data.

So after if I refresh the page, the data is loaded and html too with XHR logged with api call in browser inspect.

sometimes I don't have to refresh the page. It run properly from First Time.

So what is issue here?

Developer technologies | .NET | Blazor
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 79,101 Reputation points Volunteer Moderator
    2025-07-30T18:38:19.74+00:00

    your OnInitializedAsync() updates a state variable property, but does not force a state change. but your after render does. if after render completes after the api call updates the state data, the page works, otherwise not. move the StateHasChanged() to the OnInitializedAsync().

    note: if OnInitializedAsync() returns task not completed (it is not called with an await as all renders are sync), the component is rendered before the task completes. if the OnInitializedAsync() then calls state changed() a re-render is done. This is how your first page is able to re-render the progress bar.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.