title: Blazor Component not updating after StateHasChanged()
body: <p>I have a Blazor Server-Side page that has the following:</p>
  <pre><code>@foreach (var s in OSTs)
  {
      &lt;div class=&quot;alert&quot; style=&quot;height: 30px; background:@s.Color; color: @s.TextColor;&quot;&gt;
  
          &lt;div class=&quot;form-row&quot;&gt;
              &lt;div class=&quot;col-sm-3&quot;&gt;&lt;strong&gt;@s.Stage&lt;/strong&gt;&lt;br /&gt;@s.Description&lt;/div&gt;
              &lt;OpportunitiesStageDiv MyEditOst=&quot;@s&quot; UpdateIt=&quot;AddOrEditStage&quot;&gt;&lt;/OpportunitiesStageDiv&gt;
              &lt;div class=&quot;badge badge-primary&quot; @onclick=&quot;() =&gt; MoveItUp(s)&quot; style=&quot;cursor: pointer; width: 6rem;&quot;&gt;&lt;i class=&quot; oi oi-arrow-top&quot;&gt;&lt;/i&gt; Move Up&lt;/div&gt;
              &lt;div class=&quot;badge badge-primary&quot; @onclick=&quot;() =&gt; MoveItDown(s)&quot; style=&quot;cursor: pointer; width: 6rem;&quot;&gt;&lt;i class=&quot;oi oi-arrow-bottom&quot;&gt;&lt;/i&gt; Move Down&lt;/div&gt;
              &lt;div class=&quot;badge badge-primary&quot;&gt;@s.Id - @s.StageOrder&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>
  <p>The Component OpportunitiesStagesDiv is as follows:</p>
  <pre><code>&lt;div class=&quot;badge badge-primary&quot; @onclick=&quot;() =&gt; EditStage(MyEditOst.Id)&quot; style=&quot;cursor: pointer; width: 6rem;&quot;&gt;Edit Stage&lt;/div&gt;
  &lt;Modal @ref=&quot;@EditModal&quot;&gt;
      &lt;Title&gt;Edit Opportunity Stage&lt;/Title&gt;
      &lt;Body&gt;
          &lt;EditOpportunityStage EditOSt=&quot;@MyEditOst&quot; Complete=&quot;AddOrEditStage&quot;&gt;&lt;/EditOpportunityStage&gt;
      &lt;/Body&gt;
      &lt;Footer&gt;
          &lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-dismiss=&quot;modal&quot; @onclick=&quot;() =&gt; EditModal.Close()&quot;&gt;Close&lt;/button&gt;
      &lt;/Footer&gt;
  &lt;/Modal&gt;
  @code {
      [Parameter]
      public OpportunityStagesTemplate MyEditOst { get; set; }
      private Modal EditModal = new Modal();
      [Parameter]
      public EventCallback&lt;int&gt; UpdateIt { get; set; }
  
      protected override void OnInitialized()
      { 
          base.OnInitialized();
      }
      private void EditStage(int SId)
      {
          EditModal.Open();
      }
      private void AddOrEditStage(int Completed)
      {
          if (Completed == 99)
          {
          }
          EditModal.Close();
      }
  }
  
  </code></pre>
  <p>The MoveItUp(s) and MoveItDown(s) are functions that move the main div element in the foreach loop either up or down based on the order parameter in the query from the database. This works perfectly. What is strange is that once a DIV element is moved up or down, the edit function <code>@onclick=&quot;() =&gt; EditStage(MyEditOst.Id)&quot;</code> in the component reflects as if it is the previous element.</p>
  <p>For reference the working MoveItUp and MoveItDown functions:</p>
  <pre><code> private void MoveItUp(OpportunityStagesTemplate MyEditOst)
      {
          if (MyEditOst.StageOrder &gt; 1)
          {
              OpportunitiesStagesTemplateGateway OSTGw = new OpportunitiesStagesTemplateGateway();
              OpportunityStagesTemplate PreviousOst = OSTGw.GetStageByOIdAndStageOrder(MyEditOst.OId, MyEditOst.StageOrder - 1);
              PreviousOst.StageOrder = MyEditOst.StageOrder;
              MyEditOst.StageOrder -= 1;
              OSTGw.UpdateOpportunityStage(PreviousOst);
              OSTGw.UpdateOpportunityStage(MyEditOst);
              ExecuteTheGetStages(LastId);
              StateHasChanged();
          }
      }
      private void MoveItDown(OpportunityStagesTemplate MyEditOst)
      {
          OpportunitiesStagesTemplateGateway OSTGw = new OpportunitiesStagesTemplateGateway();
          int ct = OSTGw.GetCountByOId(MyEditOst.OId);
          if (ct &gt; MyEditOst.StageOrder)
          {
              OpportunityStagesTemplate NextOst = OSTGw.GetStageByOIdAndStageOrder(MyEditOst.OId, MyEditOst.StageOrder + 1);
              NextOst.StageOrder = MyEditOst.StageOrder;
              MyEditOst.StageOrder += 1;
              OSTGw.UpdateOpportunityStage(NextOst);
              OSTGw.UpdateOpportunityStage(MyEditOst);
              ExecuteTheGetStages(LastId);
              StateHasChanged();
          }
      }
  </code></pre>
  <p>Example I have a list as follows:</p>
  <pre><code>&lt;div 1 edit moveup movedown&gt;
  &lt;div 2 edit moveup movedown&gt;
  &lt;div 3 edit moveup movedown&gt;
  </code></pre>
  <p>When I move up one div</p>
  <pre><code>&lt;div 1 edit moveup movedown&gt;
  &lt;div 3 edit moveup movedown&gt;
  &lt;div 2 edit moveup movedown&gt;
  </code></pre>
  <p>and then click on the edit for now on line 2 for div 3, it brings up the edit as if was the div 2. It seems that the component still retains the position on the rendered UI as if DIV 2 is in on the second line and DIV 3 is still on the thirdline, although the move up and move down functions have updated the database and have updated the UI correctly to display the list in the order as it is moved. Any suggestions?</p>
  <p>Below is sample rendered page:</p>
  <p><a href="https://i.stack.imgur.com/ogbSH.png" rel="nofollow noreferrer">Sample list picture</a></p>