title: How can I make a Blazor form that only submits fields changed
body: <p>I have a Blazor form using .NET 6 and have it working with an API PUT endpoint that can update the database upon clicking a button. This takes all of the bound input fields in the form and submits them into the payload.</p>
  <p>I've modified my endpoint such that if payload is missing any attributes, it sends null and doesn't update the particular database field, essentially ensuring that only the sent changes are the items that get updated.</p>
  <p>However, I'm struggling to find an example in Blazor where the submit only sends input fields on the form that were modified. I'm new to Blazor and my original implementation just had a button that had an @onclick event, which then called the endpoint, passing the object that has data bound in the form. This works but I'd prefer that I understand how to only send the data modified to not have unrequired overwrites.</p>
  <p>Here's a mockup of what I have (truncated for readability):</p>
  <pre><code>@inject IDataSetService DataSetService
  
  @page &quot;/GameData/Data/DataSetEdit&quot;
  @page &quot;/GameData/Data/DataSetEdit/{IDRouteParam:int}&quot;
  
  
  &lt;PageTitle&gt;DataSet Edit&lt;/PageTitle&gt;
  
  
  &lt;div class=&quot;content-wrapper&quot;&gt;
  
      &lt;!-- Main content --&gt;
      &lt;section class=&quot;content&quot;&gt;
          &lt;div class=&quot;container-fluid&quot;&gt;                                   
              &lt;!-- Card --&gt;
              &lt;div class=&quot;card&quot;&gt;
                  &lt;div class=&quot;card-header&quot;&gt;
  
                  &lt;/div&gt;
                  &lt;form&gt;
                      &lt;div class=&quot;card-body&quot;&gt;     
                          
                          &lt;div class=&quot;form-group&quot;&gt;
                          &lt;label for=&quot;ID&quot;&gt;ID&lt;/label&gt;
                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;ID&quot; placeholder=&quot;12345&quot; value=&quot;@dataSet.ID&quot;&gt;
                          &lt;/div&gt;
  
                          &lt;div class=&quot;form-group&quot;&gt;
                          &lt;label for=&quot;IsActive&quot;&gt;Is Active?&lt;/label&gt;                                                                       
                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;IsActive&quot; placeholder=&quot;IsActive&quot; @bind-value=&quot;dataSet.IsActive&quot;&gt;
                          &lt;/div&gt;
  
                          &lt;div class=&quot;form-group&quot;&gt;
                          &lt;label for=&quot;IsDeleted&quot;&gt;Is Deleted?&lt;/label&gt;                        
                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;IsDeleted&quot; placeholder=&quot;IsDeleted&quot; @bind-value=&quot;dataSet.IsDeleted&quot;&gt;
                          &lt;/div&gt;
  &lt;div class=&quot;card-footer&quot;&gt;
                      &lt;button type=&quot;submit&quot; class=&quot;btn btn-info&quot; @onclick=&quot;() =&gt; UpdateDataSet()&quot;&gt;Save&lt;/button&gt;
                      &lt;button type=&quot;submit&quot; class=&quot;btn btn-danger&quot;&gt;Cancel&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;                
              &lt;/div&gt;
              &lt;!-- /.Card --&gt;
              }
          &lt;/div&gt;
      &lt;/section&gt;
  &lt;/div&gt;
  
  @code {
      private DataSet? dataSet = null;
  
      private string message = string.Empty;
  
      private bool ActiveChecked = false;
  
      private bool DeletedChecked = false;
  
      [Parameter]
      public int IDRouteParam { get; set; }
  
      protected override async Task OnParametersSetAsync()
      {
          message = &quot;Loading DataSet.. &quot;;
          var result = await DataSetService.GetDataSetByID(IDRouteParam);    
  
          if (!result.Success)
          {
              message = result.Message;
          }
          else
          {
              dataSet = result.Data;
          }
      }
  
      async void UpdateDataSet()
      {        
          dataSet= await DataSetService.UpdateDataSet(dataSet);
  
      }
  }
  </code></pre>
  <p>I have been reading on changing this to an EditForm along with an OnValidSubmit, but I haven't come across an example that shows how to detect fields that were changed and how to use those to build the payload to send to the API.</p>