Skip to content

Unable to use OnInitializedAsync() with Blazor Server render-mode="Server" #2

@Paul-Schroeder

Description

@Paul-Schroeder

I could not figure out why my WMBSCInitialSettings were getting ignored and the BlazorSlickCarousel wasn't working. I tried so many things and believe that I isolated the problem down to a finding that you must use the OnInitialized() event. In other words, I could not use the OnInitializedAsync() method. Unfortunately, the data corresponding to the images I am trying to display get downloaded using an asynchronous data service that makes a call out to a Web API (I need the async).

It seems that by the time data is returned in the OnInitializedAsync() method, where I was calling the API, the BlazorSlickCarousel can't use it. Interestingly enough, the page will still display the data, but it does so as though the carousel component does not exist.

Sample code in a .razor page:

<BlazorSlickCarousel @ref="ArtistCarousel" Configurations="CarouselSettings" >
	<BlazorSlickCarouselContent>
		@foreach (var artist in Artists)
		{
			// divs and such go here to display the content
		}
	</BlazorSlickCarouselContent>
	<BlazorSlickCarouselLoading>
		<p>Loading...</p>
	</BlazorSlickCarouselLoading>
</BlazorSlickCarousel>

Then, in a code-behind / ViewModel (will not work):

protected override async Task OnInitializedAsync()
{
	Artists = await WebApiDataServiceWA.GetArtworksAsync(pageDataRequest));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions