title: how to Send records within the loop individually with Ajax
body: <p>I want to send and save the records inside the loop one by one with Ajax.Each record has a button to send information.
  But when I want to send the record to the action method, only the information of the first record is sent.
  I also want to make a Condition that if the user selects an item from dropdown,can send the record, otherwise a message will be displayed.</p>
  <p><a href="https://i.stack.imgur.com/qQzeM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qQzeM.png" alt="enter image description here" /></a></p>
  <pre><code>@model ModiranVira.ViewModels.GhrardadViewModel
  @using ModiranVira.PublicClass
  @{
      Layout = null;
      string numSpace = &quot;#,##0.###&quot;;
  }
  
  &lt;div class=&quot;container-fluid mt-5&quot;&gt;
  
      &lt;table class=&quot;table table-bordered table-striped text-sm&quot;&gt;
  
  
  
          &lt;thead class=&quot;text-center&quot;&gt;
  
              &lt;tr style=&quot;background-color:#416992; color: white&quot;&gt;
                  &lt;th&gt;نوع قرارداد&lt;/th&gt;
                  &lt;th&gt;مبلغ&lt;/th&gt;
                  &lt;th&gt;تاریخ شروع&lt;/th&gt;
                  &lt;th&gt;تاریخ پایان&lt;/th&gt;
                  &lt;th&gt;تعین کارشناس&lt;/th&gt;
                  &lt;th&gt;عملیات&lt;/th&gt;
  
              &lt;/tr&gt;
  
          &lt;/thead&gt;
  
  
          @foreach (var item in Model.ghrardads)
          {
              &lt;tr&gt;
  
                  @switch (@item.NoeaKhadmat)
                  {
                      case 1:
                          &lt;td&gt;حسابرسی&lt;/td&gt;
  
  
                          break;
  
                      case 2:
                          &lt;td&gt;مالیاتی&lt;/td&gt;
  
                          break;
  
                      case 3:
  
                          &lt;td&gt;منابع انسانی&lt;/td&gt;
                          break;
  
                  }
  
                  &lt;td&gt;@item.MablghGhrardad&lt;/td&gt;
  
                  &lt;td&gt;
                      @item.ShoroeeProjectDate
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      @item.PayanProjectDate
                  &lt;/td&gt;
  
                  &lt;input class=&quot;d-none&quot; value=&quot;@item.id&quot; id=&quot;GhradadID&quot; /&gt;
  
                  &lt;td&gt;
  
                      &lt;select class=&quot;form-control&quot; id=&quot;TaeenKarShnas&quot; required autocomplete=&quot;off&quot;&gt;
                          &lt;option value=&quot;&quot; default=&quot;&quot; selected=&quot;&quot;&gt;انتخاب کنید&lt;/option&gt;
                          @foreach (var item1 in Model.Users)
                          {
                              &lt;option value=&quot;@item1.Id&quot;&gt;@item1.FirstName @item1.Family&lt;/option&gt;
  
                          }
                      &lt;/select&gt;
  
                  &lt;/td&gt;
  
                  &lt;td class=&quot;text-center&quot;&gt;
  
                      &lt;button id=&quot;btnstap39&quot; type=&quot;button&quot; class=&quot;btn btn-sm btn-outline-success&quot;&gt; &lt;i class=&quot;fa fa-save&quot;&gt; &lt;/i&gt;ذخیره &lt;/button&gt;
  
                  &lt;/td&gt;
  
              &lt;/tr&gt;
  
          }
  
      &lt;/table&gt;
  
   &lt;div id=&quot;ohsnap&quot; class=&quot;col-md-4 col-xs-12 alert d-none&quot; style=&quot;text-align:center;&quot;&gt;&lt;/div&gt;
  
  &lt;/div&gt;
  
  
  &lt;script&gt;
          $(&quot;#btnstap39&quot;).on('click', function () {
  
          $.ajax({
              type: &quot;Post&quot;,
              url: '@Url.Action(&quot;SubmitGhrardadStap39&quot;, &quot;Project&quot;)',
              data: {
  
                  'GhradadID': $(&quot;#GhradadID&quot;).val(),
                  'TaeenKarShnas': $(&quot;#TaeenKarShnas&quot;).val(),
  
              }
          }).done(function (res) {
              if (res.status == 'ok') {
  
              $(&quot;#ohsnap&quot;).removeClass('hidden').removeClass('alert-danger').addClass('alert-success').html('گام دوم با موفقیت ثبت شد');
          setTimeout(function () {
              $('#ohsnap').fadeOut('fast');
          }, 2000)
          }
          });
  
          });
  
  &lt;/script&gt;
  </code></pre>
  <hr />
  <pre><code>[HttpPost]
  public IActionResult SubmitGhrardadStap39(int GhradadID, String TaeenKarShnas)
  {
      var ghrar = _context.Ghrardad.Find(GhradadID);
  
      ghrar.UserID = TaeenKarShnas;
  
      _context.SaveChanges();
  
      return Json(new { status = &quot;ok&quot; });
  
  }
  </code></pre>