title: angular2 "400 Bad Request" on POST Request
body: <p>When I do a POST I get the error POST <a href="http://localhost:5000/api/activities" rel="nofollow noreferrer">http://localhost:5000/api/activities</a> 400 (Bad Request)
  But when I add a id my put works perfect.</p>
  
  <p>Can somebody help me, I don't find the solution. Why do I get the 400 (Bad Request) Error?</p>
  
  <p>Here is my code:</p>
  
  <p>in global:</p>
  
  <pre><code>BASE_URL_API = 'http://localhost:5000/api/'
  </code></pre>
  
  <p>in activitiy.service.ts</p>
  
  <pre><code>private activitiesUrl = this.globals.BASE_URL_API + 'activities';
  
  //POST
  private post(activity: Activity): Promise&lt;Activity&gt; {
  let headers = new Headers({
    'Content-Type': 'application/json'
  });
  
  return this.http
    .post(this.activitiesUrl, JSON.stringify(activity), { headers: headers })
    .toPromise()
    .then(res =&gt; res.json().data)
    .catch(this.handleError);
   }
  // Update existing Activity
  private put(activity: Activity): Promise&lt;Activity&gt; {
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
  
    let url = `${this.activitiesUrl}/${activity.id}`;
  
    return this.http
      .put(url, JSON.stringify(activity), { headers: headers })
      .toPromise()
      .then(() =&gt; activity)
      .catch(this.handleError);
  }
  </code></pre>
  
  <p>in addActivity.ts</p>
  
  <pre><code>activityCredentials = {
  id: null,
  name: 'test', 
  description: 'test description',
  locationId: 2,
  activityTypeId: 2,
  };
  
  ... 
  
  public save(){
      this.activityService.save(this.activityCredentials).then(success =&gt; {
       if (success) {
          this.createSuccess = true;
            this.showPopup("Success", "Activity added.");
        } else {
          this.showPopup("Error", "Problem adding activities.");
        }
      },
      error =&gt; {
        this.showPopup("Error", error);
      });
    } 
  </code></pre>
  
  <p>in ASP.NET API</p>
  
  <pre><code>[HttpPost(Name = "CreateActivity")]
      public async Task&lt;IActionResult&gt; CreateActivity([FromBody] Activity item)
         {
             if(item == null)
             {
                 return BadRequest();
             }
  
            ApplicationDbContext.Activities.Add(item);
             await ApplicationDbContext.SaveChangesAsync();
  
             return this.CreatedAtRoute("GetActivityById", new { Controller = "ActivitiesController", activityId = item.Id }, item);
         }
  
         [HttpPut("{activityId:int}", Name = "UpdateActivity")]
         public async Task&lt;IActionResult&gt; UpdateActivity(Int16 activityId, [FromBody] Activity item)
         {
             if(item == null || item.Id != activityId)
             {
                 return BadRequest();
             }
  
             var model = await ApplicationDbContext.Activities.FirstOrDefaultAsync(o =&gt; o.Id == activityId);
  
             if(model == null)
             {
                 var msg = String.Format(FAILGETENTITYBYID, activityId);
                 return NotFound(msg);
             }
  
             model.Name = item.Name;
             model.Description = item.Description;
             model.LocationId = item.LocationId;
             model.ActivityTypeId = item.ActivityTypeId;
  
             ApplicationDbContext.Activities.Attach(model);
             ApplicationDbContext.Entry(model).State = EntityState.Modified;
             await ApplicationDbContext.SaveChangesAsync();
  
             return new NoContentResult();
         }
  </code></pre>
  
  <p>I don't get the problem. Can somebody help me please?</p>