title: Every row is executed twice
body: <p>I have found a bug - and I haven't found any solution to this.</p>
  
  <p>I have a code in ASP.NET Core (using VSPro 2019 16.5.0):</p>
  
  <pre><code>public IActionResult CreateSubGroup(MyClass model, string returnUrl = null)
          {
              if (ModelState.CreateMyClassValidation())
              {
                  if (!db.MyClass.Where(x =&gt; x.Title == model.Title).Any())
                  {
                      ViewData["ReturnUrl"] = returnUrl;
                      var code = new MyClass { Title = model.Title, IdGroup = model.IdGroup, GroupCode = model.GroupCode};
                      db.MyClass.Add(code);
                      var result = db.SaveChanges();
                      if (result &gt; 0)//if there was no issue (at least one row was changed)
                      {
                          this.AddNotification(MessagesHandler.Success, $"Item\"{model.Title}\" was successfully created.");
                      }
                      else
                      {
                          this.AddNotification(MessagesHandler.Error, $"Item \"{model.Title}\" cannot be created.");
                      }
                  }
                  else
                  {
                      this.AddNotification(MessagesHandler.Error, $"Item \"{model.Title}\" already exists.");
                  }
              }
              else
              {
                  this.AddNotification(MessagesHandler.Error, $"ErrorMessage.");
              }
              return RedirectToLocal(returnUrl);
          }
  </code></pre>
  
  <p>Creating of new Item always crashes with unique code exception from DB - During debuging I have found, that every row is executed twice (and I don't know why??) - so also the row db.SaveChanges() is executed twice and that's why I got this exception.</p>
  
  <p>Second bad thing is, that not even the first attempt to save database is not executed (= new Item is not created in DB).</p>
  
  <p>Have you seen this error?</p>
  
  <p>EDIT:</p>
  
  <p>I have found, that it happens only when data are posted from view with JS/AJAX (from modal window)</p>
  
  <p>Here is the code for sending data:</p>
  
  <pre><code>&lt;div class="modal fade" id="ModalWindow" tabindex="-1" role="dialog" aria-labelledby="ModalForm" aria-hidden="true"&gt;
              &lt;div class="modal-dialog modal-dialog-centered" role="document"&gt;
                  &lt;div class="modal-content"&gt;
                      &lt;div class="modal-header"&gt;
                          &lt;h5 class="modal-title"&gt;&lt;/h5&gt;
                          &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                              &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                          &lt;/button&gt;
                      &lt;/div&gt;
                      &lt;form id="ModalForm" action="" method="post" class="validator"&gt;
                          &lt;div class="modal-body"&gt;
                              &lt;div class="form-group"&gt;
                                  &lt;label asp-for="Id"&gt;&lt;/label&gt;
                                  &lt;input class="form-control" asp-for="Id" value="" readonly data-val="false"&gt;
                                  &lt;div class="form-text text-muted small"&gt;ID cannot be changed!&lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group"&gt;
                                  &lt;label asp-for="Title"&gt;&lt;/label&gt;
                                  &lt;input class="form-control mlfb-create" asp-for="Title" placeholder="Title" value="" autofocus tabindex="@(++tabindex)"&gt;
                                  &lt;span class="text-danger small" asp-validation-for="Title"&gt;&lt;/span&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group"&gt;
                                  &lt;label asp-for="IdGroup"&gt;&lt;/label&gt;
                                  &lt;select class="selectpicker form-control" asp-for="IdGroup" data-live-search="true" data-style="btn-info" tabindex="@(++tabindex)"&gt;
                                      @if (data?.GroupData != null)
                                      {
                                          @foreach (var item in data?.GroupData)
                                          {
                                              &lt;option value="@(item.Id)"&gt;@item.Title&lt;/option&gt;
                                          }
                                      }
                                  &lt;/select&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group"&gt;
                                  &lt;label asp-for="GroupCode"&gt;&lt;/label&gt;
                                  &lt;input class="form-control mlfb-create" asp-for="GroupCode" placeholder="Title" value="" autofocus tabindex="@(++tabindex)"&gt;
                                  &lt;span class="text-danger small" asp-validation-for="GroupCode"&gt;&lt;/span&gt;
                              &lt;/div&gt;
  
                          &lt;/div&gt;
                          &lt;div class="text-center modal-footer"&gt;
                              &lt;button type="submit" class="btn btn-success _modal-buttton-save" tabindex="@(++tabindex)"&gt;&lt;i class="fas fa-check mr-2"&gt;&lt;/i&gt;&lt;span&gt;Save&lt;/span&gt;&lt;/button&gt;
                              &lt;button type="reset" class="btn btn-secondary" data-dismiss="modal"&gt;&lt;i class="fas fa-times mr-2"&gt;&lt;/i&gt;Cancel&lt;/button&gt;
                          &lt;/div&gt;
  
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  @section scripts {
      &lt;script&gt;
          $(function () {
              "use strict";
  
              $(document).on('click', '._createSubFormButton', function () {
                  $('#ModalWindow').modal('show');
  
                  $('.modal-title').text('Creating of subgroup');
  
                  $('.modal-buttton-save span').text('Create');
  
                  $('#ModalForm').attr('action', '/MyCode/CreateSubGroup/?returnurl=' + window.location.href);
              });
  
              // Edit form
              $(document).on('click', 'tr ._editSubFormButton', function () { 
                  $('#ModalWindow').modal('show');
                  var $tr = $(this).closest('tr');
  
                  var Id = $tr.find('._Id').text();
                  var Title = $tr.find('._Title').text();
                  var IdGroup = $tr.find('._IdGroup').text();
                  var GroupCode = $tr.find('._GroupCode').text();
  
                  $('.modal-title').text('Editing of subgroup');
                  $('#ModalForm').attr('action', '/MyCode/EditSubGroup/' + Id + '?returnurl=' + window.location.href);
                  $('#Id').val(Id);
                  $('#Title').val(Title);
                  $('#GroupCode').val(GroupCode);
              });
  
              // form validation reset during closing modal form
              $('#ModalWindow').on('hidden.bs.modal', function () {
                  $(this).find('form').trigger('reset');
                  $('#IdGroup').load();
                  $('.form-group .is-invalid').each(function () { $(this).removeClass('is-invalid'); });
                  $('.form-group .is-valid').each(function () { $(this).removeClass('is-valid'); });
                  $('.form-text.text-danger').each(function () { $(this).removeClass('text-danger'); });
                  $('.form-text.text-success').each(function () { $(this).removeClass('text-success'); });
                  $('.invalid-feedback').each(function () { $(this).remove(); });
              });
  $(document).on('submit', '#ModalForm', function (e) {
              var form = $('#ModalForm');
  
              if (form.valid()) {
  
                  console.log(form.serializeArray());
  
  
                  $.ajax({
                      url: form.attr("action"),
                      type: form.attr("method"),
                      data: form.serializeArray()
  
                  }).done(function () {
                      console.log('done');
                      $tr.find('._Number').text();
                      var $tr = $(this).closest('tr');
                  })
                      .fail(function () {
                          console.log('fail');
                      });
  
                  $('#ModalWindow').modal('hide');
              }
          });
  </code></pre>
  
  <p>error I got:
  <a href="https://i.stack.imgur.com/Y2SEJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y2SEJ.png" alt="Error message"></a></p>