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

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