I have an array of objects in which there is an IsChecked
property.
With an array I fill the table, where for the IsChecked
properties I do @bind to input.
When I try to switch the value, an error flies.
If I immediately change the value IsChecked = true
, then the check mark is ticked.
for(var i = 0; i < firms.Length; i++)
{
<tr>
<td>@firms[i].ShortTitle</td>
<th scope="row">
<div class="custom-control custom-checkbox">
<input type="checkbox" ... @bind="@firms[i].IsChecked" />
..
</div>
</th>
</tr>
}
Error:
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: Index was outside the bounds of the array.
System.IndexOutOfRangeException: Index was outside the bounds of the array. at ....<>c__DisplayClass0_1.b__6(Boolean __value) at Microsoft.AspNetCore.Components.EventCallbackFactoryBinderExtensions.<>c__DisplayClass22_0`1.b__0(ChangeEventArgs e) --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle) Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'LzL8iNZr7FmkJFJRS3QTW3QzJwP9R-p3CaclRHcE1_A.'.
System.IndexOutOfRangeException: Index was outside the bounds of the array. at ...<>c__DisplayClass0_1.b__6(Boolean __value) at Microsoft.AspNetCore.Components.EventCallbackFactoryBinderExtensions.<>c__DisplayClass22_0`1.b__0(ChangeEventArgs e) --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
what am I doing wrong?