title: How to add onclick event to radio button in Razor View
body: <p>I have this view. It's ok besides that I want to add: <code>onclick="javascript:SubmitClick(@Model.id, answer.Id);"</code> to definition of RadioButtons in it.</p>
  
  <pre><code>@model WebApplication2.Models.Question
  &lt;div&gt;
      @Html.HiddenFor(x =&gt; x.Id)
      &lt;h3&gt; @Model.QuestionText &lt;/h3&gt;
      @foreach (var answer in Model.Answers) {
          &lt;p&gt;
              @Html.RadioButtonFor(b =&gt; b.SelectedAnswer, answer.Id)  @answer.AnswerText
          &lt;/p&gt;
      }
  &lt;/div&gt;
  </code></pre>
  
  <p>Question and Answer are models which look like that. </p>
  
  <pre><code> public class Question {
          public int Id { set; get; }
          public string QuestionText { set; get; }
          public virtual ICollection&lt;Answer&gt; Answers { set; get; }
          public string SelectedAnswer { set; get; } //this field is SET after clicking the radio button, I don't need this field ant this behaviour
  
      }
      public class Answer {
          public int Id { set; get; }
          public string AnswerText { set; get; }
      }
  </code></pre>
  
  <p>As far as I know <code>b =&gt; b.SelectedAnswer</code> this expression inside <code>@Html.RadioButtonFor</code> makes that after click the field <code>SelectedAnswer</code> in class <code>Question</code> will be set. I don't need that I only need that only one of those radio buttons inside foreach loop can be selected at the same time and clicking on them invokes <code>onclick="javascript:SubmitClick(@Model.id, answer.Id);"</code>. Also it can be done in obsolete way, just to make it work.</p>
  
  <p>Screen which will help undestand how the view looks:</p>
  
  <p><img src="https://i.stack.imgur.com/zfHHV.png" alt="enter image description here"></p>