title: Cant update second or third loop in foreach using Ajax - MVC
body: <p>In my razor page i have an foreach and i loop an Dropdown list where user can select something and then update dropdown list by click on button, first dropdown list can updated with no problem, but when it comes to dropdown second and third  it <code>cant</code> updated.i also dubgged and i can see it, it will pass value to controller , but it cant update DB. Can anyone please help me or point me in the right direction! <br>
  Thanks in advance :)</p>
  
  <p>View:</p>
  
  <pre><code>    &lt;tbody&gt;
       @foreach (var rma in Model)
          { 
      &lt;tr&gt;
      &lt;td style="display:none;"&gt;
      &lt;input type="hidden" name="Id" id="Id" value="@rma.Id" /&gt;
      &lt;/td&gt;
    &lt;td&gt;
   @if (rma.NTFonoff == "Ja")
   {
      &lt;select class="form-control border-input" id="ddlupdateOne"&gt;
  
       &lt;option value="Ja"&gt;@rma.NTFonoff&lt;/option&gt;
       &lt;option value="Nej"&gt;Nej&lt;/option&gt;
       &lt;/select&gt;
  
      &lt;div id="dvOne" style="display: none"&gt;
       &lt;button type="submit" id="btnone"&gt;Send 1&lt;/button&gt;
        &lt;/div&gt;
  
        }
  
         else if (rma.NTFonoff == "Nej")
       {
      &lt;select  class="form-control border-input" id="ddlupdateTwo"&gt;
      &lt;option value="@rma.NTFonoff"&gt;@rma.NTFonoff&lt;/option&gt;
      &lt;option value="Ja"&gt;Ja&lt;/option&gt;
      &lt;/select&gt;
      &lt;div id="dvTwo" style="display: none"&gt;
       &lt;button type="submit" id="btntwo"&gt;Send 2&lt;/button&gt;
       &lt;/div&gt;
  
       }
       &lt;/td&gt;
      &lt;/tr&gt;
         }
      &lt;/tbody&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public JsonResult UpdateNtf(string SelectedNTFText, int? Id)
  {
      var ntf = db.RMA_History.Where(a =&gt; a.Id == Id).FirstOrDefault();
  
      if (ntf != null)
      {
          ntf.NTFOnOFF = SelectedNTFText;
          db.SaveChanges();
      }
      return Json(ntf, JsonRequestBehavior.AllowGet);
  
  }
  </code></pre>
  
  <p>JavaScript <strong>(btntwo)</strong>:</p>
  
  <pre><code>&lt;script&gt;
  
      $(document).ready(function () {
  
          $('#btntwo').click(function (e) {
              e.preventDefault();
  
              var id = $("#Id").val();
  
              var SelectedNTFText = $("#ddlupdateTwo option:selected").text();
  
                 $.ajax({
                  type: "POST",
                  url: '@Url.Action("UpdateNtf", "Account")',
                     data: {
                         Id: id,
                         SelectedNTFText: SelectedNTFText
                  },
                  dataType: 'json',
                  success: function (result) {
  
                      if (result) {
  
                          result.NTFOnOFF = SelectedNTFText;
  
  
                          console.log("Ok")
                      } else {
  
                          console.log("error");
                      }
  
  
  
                  },
                  error: function () {
                      console.log('something went wrong - debug it!');
                  }
              })
  
          });
  
  
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>JavaScript <strong>(btnone)</strong>:</p>
  
  <pre><code>&lt;script&gt;
     $(document).ready(function () {
  
         $('#btnone').click(function (e) {
              e.preventDefault();
  
              var id = $("#Id").val();
  
             var SelectedNTFText = $("#ddlupdateOne option:selected").text();
  
                 $.ajax({
                  type: "POST",
                  url: '@Url.Action("UpdateNtf", "Account")',
                     data: {
                         Id: id,
                         SelectedNTFText: SelectedNTFText
                  },
                  dataType: 'json',
                  success: function (result) {
  
                      if (result) {
  
                          result.NTFOnOFF = SelectedNTFText;
  
  
                          console.log("Ok")
                      } else {
  
                          console.log("error");
                      }
  
  
  
                  },
                  error: function () {
                      console.log('something went wrong - debug it!');
                  }
              })
  
          });
  
  
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>JavaScript <strong>(Show DDL base on Select)</strong>:</p>
  
  <pre><code>&lt;script&gt;
      $("#ddlupdateOne").change(function () {
          if ($(this).val() == "Ja") {
              $("#dvOne").show();
          }
          if ($(this).val() == "Nej") {
              $("#dvOne").show();
          }
  
      });
  
  
      $("#ddlupdateTwo").change(function () {
          if ($(this).val() == "Ja") {
              $("#dvTwo").show();
          }
          if ($(this).val() == "Nej") {
              $("#dvTwo").show();
          }
  
      });
  
  &lt;/script&gt;
  </code></pre>