title: Why is my data binding not working and is always null?
body: <p>I am trying to add data to the database. I experimenting with <code>Blazor</code> and <code>.NET core</code>:</p>
  
  <p>This is my code in the controller:</p>
  
  <pre><code> [Route("AddCarBlazor")]
   [HttpPost]
          public IActionResult PostBlazor(Car car)
          {
              if (car.CarId == 0)
              {
                  // New
                  car.Created = DateTime.Now;
                  _context.Cars.Add(car);
                  _context.SaveChanges();
                  return Ok();
              }
              else
              {
                  // Update
                  var c = _context.Cars.First(e =&gt; e.CarId == car.CarId);
                  c.Brand = car.Brand;
                  c.Color = car.Color;
                  c.Model = car.Model;
                  c.LastChange = DateTime.Now;
                  c.TopSpeed = car.TopSpeed;
                  _context.SaveChanges();
                  return Ok();
              }
          }
  </code></pre>
  
  <p>My <strong>car</strong> model looks like this:</p>
  
  <pre><code>public class Car
      {
          [Key]
          public long CarId { get; set; }
          public string Created { get; set; }
          public string LastChange { get; set; }
          public string Brand { get; set; }
          public string Model { get; set; }
          public string Color { get; set; }
          public long TopSpeed { get; set; }
      }
  </code></pre>
  
  <p>I call this method like this:</p>
  
  <pre><code>  private async Task AddCar()
      {
          await Http.PostJsonAsync(baseUrl + "/AddCarBlazor/", carobject);
          await Refresh();
      }
  </code></pre>
  
  <p>When I fill in the form and press <strong>add</strong> button the <strong>car object</strong> is always <strong>null</strong></p>
  
  <p>This is my form with the databinding:</p>
  
  <pre><code>&lt;form&gt;
      &lt;div class="row"&gt;
          &lt;div class="form-group col-sm-3"&gt;
              &lt;label&gt;Brand&lt;/label&gt;
              &lt;input input type="text" @bind="@carobject.Brand" class="form-control" placeholder="Enter brand" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;div class="form-group col-sm-3"&gt;
              &lt;label&gt;Model&lt;/label&gt;
              &lt;input type="text" @bind="@carobject.Model" class="form-control" placeholder="Enter model" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;div class="form-group col-sm-3"&gt;
              &lt;label&gt;Color&lt;/label&gt;
              &lt;input type="text" @bind="@carobject.Color" class="form-control" placeholder="Enter color" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;div class="form-group col-sm-3"&gt;
              &lt;label&gt;TopSpeed&lt;/label&gt;
              &lt;input type="number" @bind="@carobject.TopSpeed" class="form-control" placeholder="Enter speed" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="btn-group mr-2"&gt;
          &lt;button class="btn btn-danger mr-1" onclick=@AddCar&gt;Save changes&lt;/button&gt;       
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I have put a breakpoint on the <strong>addCar</strong> method. I get the values from the fields but when it goes to the controller it becomes <strong>null</strong>. </p>
  
  <p>I have following this tutorial:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-3.0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-3.0</a></p>
  
  <p>How can I save the values from the fields and send it to the database? </p>