© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
gax

Generating input fields for each element in an array in Blazor WASM

I'm trying to generate an input field for each element in an array, and have the input field bind that element to the array, however, no matter how i do it, it either throws an exception or doesn't bind at all.

This is basically what I have right now

<div style="display: grid; grid-template-columns: repeat(3, 50px); gap: 10px;">
    @for (int i = 0; i < a.Length; i++)
    {
        <input type="text" style="width: 50px" placeholder="@i" @bind-value="a[i]" @key="i"/>
    }
</div>

@code {
  private string[] a = new string[9];
}
<div style="display: grid; grid-template-columns: repeat(3, 50px); gap: 10px;">
    @for (int i = 0; i < a.Length; i++)
    {
        <input type="text" style="width: 50px" placeholder="@i" @bind-value="a[i]" @key="i"/>
    }
</div>

@code {
  private string[] a = new string[9];
}

Currently, it generates the input fields, but when attempting to change values, it throws an IndexOutOfRangeException
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Configure JsonSerializationOptions for WASM Interop in Blazor?
C#CC# / help
9mo ago
✅ Blazor WASM Headers
C#CC# / help
4mo ago