Search code examples
blazorrazor-pagesrazor-components

Several Razor Components in one Razor Page


The problem is the following. There is a Razor Page project (a hybrid of Blazor). One of the pages uses two Razor Components in ServerPrerendered mode. Initialization of each of them requires loading data from the database. When only one component on the page is involved, there are no problems - everything works as expected, including interactivity. But if you use two components at the same time, something incomprehensible happens - only one of the components is initialized correctly, each time it is different. I can't figure out where to look, because in debugging mode with breakpoints everything works out correctly. Tell me, please, what could be the catch?

Initializing one of the components

protected override async Task OnInitializedAsync()
{
    var postRating = await koooirDbContext.PostRatings
        .FirstOrDefaultAsync(f => f.PostId == PostId);
    if (postRating != null)
    {
        current = new CurrentRating
            {
                Rating = postRating.Rating,
                Votes = postRating.Votes
            };
    }
    dataIsLoaded = true;
}

Solution

  • The question is removed. The problem was sharing DbContext. Solution.