title: How to determine which radio button was selected in C# ASP.NET CORE MVC 5.0
body: <p>I am wanting to check to see which radio button was selected from my <code>Index.cshtml</code> file and from there I would like to use a switch statement to set attributes to its object. I was reading up on how to do this but majority of them were for groups in a windows form but that would not apply to me since I am using a asp.net core 5.0 web mvc project.</p>
  <p>In my <code>Index.cshmtl</code> I have the following:</p>
  <pre><code>....
  &lt;form action=&quot;@Url.Action(&quot;SecIndex&quot;, &quot;Second&quot;)&quot;&gt;
  
      &lt;input type=&quot;radio&quot; value=&quot;1&quot; /&gt;&lt;label&gt;Valid&lt;/label&gt;
      &lt;input type=&quot;radio&quot; value=&quot;2&quot; /&gt;&lt;label&gt;Wrong&lt;/label&gt;
      &lt;input type=&quot;radio&quot; value=&quot;3&quot; /&gt;&lt;label&gt;InValid&lt;/label&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Address Validation&quot; /&gt;
  
  &lt;/form&gt;
  </code></pre>
  <p>then in my <code>HomeController</code>, I have the following method:</p>
  <pre><code>        [HttpPost]
          public IActionResult ValidateAddress()
          {
              // if radio button was checked, perform the following var request.
  
  
              var check = &quot;&quot;; // this should be able to grab the label of the button that was selected
  
              switch (check)
              {
                  case &quot;Valid&quot;:
                     var request = new AddressRequest
                      {
                          StatusCode = 1,
                          Address = &quot;2018 Main St New York City, NY, 10001&quot;
                      };
                      break;
                  case &quot;Wrong&quot;:
                      var req = new AddressRequest
                      {
                          StatusCode = 2,
                          Address = &quot;91 Apple City Galveston, TX, 77550&quot;
                      };
                      break;
                  case &quot;Invalid&quot;:
                      var addressRequest = new AddressRequest
                      {
                          StatusCode = 3,
                          Address = &quot;00000 Tree Ln, Miami FL 91041&quot;
                      };
                      break;
              }
  
              return View();
          }
  </code></pre>
  <p>But I cannot seem to figure out how to allow variable <code>check</code> to perform a check to see which radio button was selected since this is a asp.net core 5.0 web mvc project and not a windows form. Is there a way to do this in this type of project?</p>
  <hr />
  <p><strong>UPDATE:</strong></p>
  <p>So I realized that I wanted to have the Value as it was before with numbers. So implementing the suggestion, I needed to still redirect the user to the method <code>SecIndex</code> in my <code>Second</code> controller. However, I still needed to grab the value of radio button that was selected. So I attempted to do <code>return RedirectToAction(&quot;SecIndex&quot;);</code> but when I ran the program and hit the button to validate it gave me:</p>
  <blockquote>
  <p>This page isn't working. If the problem continues, contact the site owner.
  HTTP ERROR 405</p>
  </blockquote>
  <p>Did I do something incorrectly? the URI shows up as <code>https://localhost:5443/Home/ValidateAddress?Status=1</code>. Not I did select the first option, which should give me Status as 1. Not sure why it is returning that though.</p>
  <p>Inside of my <code>HomeController</code>:</p>
  <pre><code>       [HttpPost]
          public IActionResult ValidateAddress(string validate)
          {
              // if radio button was checked, perform the following var request.
  
              switch (validate)
              {
                  case &quot;Valid&quot;:
                     var request = new AddressRequest
                      {
                          StatusCode = 1,
                          Address = &quot;2018 Main St New York City, NY, 10001&quot;
                      };
                      break;
                  case &quot;Wrong&quot;:
                      var req = new AddressRequest
                      {
                          StatusCode = 2,
                          Address = &quot;91 Apple City Galveston, TX, 77550&quot;
                      };
                      break;
                  case &quot;Invalid&quot;:
                      var addressRequest = new AddressRequest
                      {
                          StatusCode = 3,
                          Address = &quot;00000 Tree Ln, Miami FL 91041&quot;
                      };
                      break;
              }
  
              return RedirectToAction(&quot;SecIndex&quot;);
          }
  
      }
  </code></pre>
  <p><code>Home View... index.cshtml</code>:</p>
  <pre><code>&lt;form action=&quot;@Url.Action(&quot;ValidateAddress&quot;, &quot;Home&quot;)&quot;&gt;
  
      &lt;input type=&quot;radio&quot; value=&quot;1&quot; name=&quot;Status&quot;/&gt;&lt;label&gt;Valid&lt;/label&gt;
      &lt;input type=&quot;radio&quot; value=&quot;2&quot; name=&quot;Status&quot;/&gt;&lt;label&gt;Wrong&lt;/label&gt;
      &lt;input type=&quot;radio&quot; value=&quot;3&quot; name=&quot;Status&quot;/&gt;&lt;label&gt;InValid&lt;/label&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Address Validation&quot; /&gt;
  
  &lt;/form&gt;
  </code></pre>