title: How do you correctly wire up dynamically created buttons in Blazor?
body: <p>I'm fairly new to web frontend, but thought it would be great to have toggle buttons for every 'flaw' in a matrix I was displaying (so you can choose a path backtracing up the matrix).</p>
  
  <p>Luckily, I figured out how to make buttons dynamically in Blazor... Unfortunately, I can't seem to figure out how to 'wire' the buttons.</p>
  
  <p>If I was statically making a button, I could say onclick="@(()=>alignment.ChangeArrow(1))" for the first flaw location, replace the 1 with a 2 for the second, etc...</p>
  
  <p>Giving it 1 (instead of i) in the below code snippet makes all the buttons work for the 1st flaw, but if I give it the variable i then it doesn't work at all?</p>
  
  <pre><code>@for (int i = 0; i &lt; alignment.FlawList.Count; i++)
  {
      &lt;button class="button" style="background-color:@alignment.ReturnColor(i)" onclick="@(()=&gt;alignment.ChangeArrow(i))"&gt;@alignment.FlawList[i] @i&lt;/button&gt;
  }
  </code></pre>
  
  <p>Is there a better Blazor, web way to do what I am talking about?</p>
  
  <p>Thanks for any guidance.</p>