title: How do I get data from a radio/checkbox form submission in the Blazor @code block?
body: <p>I am making a quiz/exam page that uses a Question component. The questions contain answers with either a checkbox or radio selection and a submit button. I need to be able to compare the <em>selected</em> answer(s) to the correct answer <em>when a user clicks submit</em> (or some other button type), but I am not sure how to get the value of the input inside of my @code block for processing.</p>
  
  <p>I've messed around with @bind-value but it doesn't seem to relate to the button click at all and I only want the value from one answer, the selected one.</p>
  
  <p>So far using a "submit" button doesn't seem to be the right route because it does a POST request, which is not the behavior I'm looking for. I just want the button to trigger processing in the component.</p>
  
  <p>Here is my component</p>
  
  <pre><code>&lt;form&gt;
      &lt;div class="q-card"&gt;
          &lt;h3&gt;@Question.QuestionText&lt;/h3&gt;
          @foreach (var option in Question.Options)
          {
              &lt;div&gt;
                  &lt;input type="@Question.InputType" id="@answer" name="@Question.Id" value="@answer"/&gt;
                  &lt;label for="@answer"&gt;@answer&lt;/label&gt;
              &lt;/div&gt;
          }
          &lt;div class="q-controls"&gt;
              &lt;button type="submit"@onsubmit="@OnSubmit"&gt;Submit&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and my @code block</p>
  
  <pre><code>@code {
      public string answer;
  
      public void OnSubmit()
      {
          System.Console.WriteLine(answer);
      }
  }
  </code></pre>
  
  <p>I want the value from the selection to end up in the variable <code>answer</code> when I click Submit. I realize if there are multiple answers (checkbox) I'll need to change this variable, but I'll get to that later.</p>