How can I trigger/refresh my main .RAZOR page from all of its sub-components within that main .RAZOR page when an API call is complete?

The answer shows how to update the Blazor WeatherForecast application to demonstrate the state/notification pattern and how to use it in components. I’ve used the Weather Forecast application because there’s not enough detail in your question to use your code as the basis for an answer, and the Weather Forecast application provides a good template … Read more

Display wait or spinner on API call

Option 1: Using Task.Delay(1) Use an async method. Use await Task.Delay(1) or await Task.Yield(); to flush changes private async Task AsyncLongFunc() // this is an async task { spinning=true; await Task.Delay(1); // flushing changes. The trick!! LongFunc(); // non-async code currentCount++; spinning=false; await Task.Delay(1); // changes are flushed again } Option 1 is a simple … Read more

For loop not returning expected value – C# – Blazor

Your for loop should contain a local variable like this: @for (int i = 0; i < Math.Ceiling((decimal)articleService.ReturnAll().Count() / numPerPage); i++) { var localVariable = i; <li class=”page-item”><a class=”page-link” onclick=”@(() => ReturnPage(localVariable ))”>@i</a></li> } This is standard C# behavior where lambda expression @(() => ReturnPage(localVariable )) has access to a variable and not to the … Read more

How to use the HttpContext object in server-side Blazor to retrieve information about the user, user agent

The fiction that the HttpContext object can’t be used with Blazor Server App, has been long propagated on Stackoverflow, and it is high time to pension it off. It is true that the HttpContext is not available when a WebSocket connection is in operation, but this must be clear: When you type an url and … Read more

Cannot debug Blazor wasm

I managed to get it working with Microsoft’s Edge browser. Although I’m using VSCode on linux, it should be similar for Visual Studio on Windows / Mac, because I believe the underlying Roslyn-based tooling is the same. Update dependencies Ensure you’re using the latest SDK version: 6.0.202. Check using dotnet –version. Install Edge Get the … Read more

Calling function from generated button in Blazor

I guess you should add a local variable to your loop as follows: @for (int i = 0; i < Buttons.Count; i++) { var local = i; <button type=”button” class=”btn btn-primary btn-lg” style=”margin:10px” onclick=”@((ui) => ButtonClicked(local))”>@Buttons[i]</button> } This is a standard C# behavior, not related to Blazor, where the lambda expression @((ui) => ButtonClicked(i)) has … Read more

Blazor – Display wait or spinner on API call

Option 1: Using Task.Delay(1) Use an async method. Use await Task.Delay(1) or await Task.Yield(); to flush changes private async Task AsyncLongFunc() // this is an async task { spinning=true; await Task.Delay(1); // flushing changes. The trick!! LongFunc(); // non-async code currentCount++; spinning=false; await Task.Delay(1); // changes are flushed again } Option 1 is a simple … Read more