I'm having an index out of bounds issue on one of my razor pages, even though it is in a for loop ensuring it's not out of bounds. This is a page for uploading a mini that the user has created with what paints were used on what parts (i.e. body armor was painted "Blue" etc...). This is a slightly complicated model, so if I need to add more info I will, but I'm trying to keep the code as small as possible to make it easier to review. Thanks in advance for the help!
@foreach (var elem in newMini.Elements)
{
<div class="@elem.Name">
<InputText @bind-Value="elem.Name" placeholder="Element name" />
@for (int i = 0; i < elem.PaintsUsed.Count; i++)
{
<div class="@elem.PaintsUsed[i]">
index: @i of count: @elem.PaintsUsed.Count
<input type="text"
list="paint-search"
placeholder="Search from @allPaints.Count() paints!"
@bind="@elem.PaintsUsed[i]" />
<datalist id="paint-search">
@foreach (var paint in allPaints)
{
<option>@paint.PaintName</option>
}
</datalist>
</div>
}
@if (!String.IsNullOrWhiteSpace(elem.Name))
{
<button type="button" @onclick="() => AddPaintToElement(elem)">
Add Paint To Element
</button>
}
</div>
}
EDIT: Here's a link to the file and my repo, if you need more background. https://github.com/Zami77/wargamer_showcase/blob/main/Pages/MiniUpload.razor