title: AngularJS ngResource POST object is Null in C# Web API
body: <p>My problem is that when I send a complete Javascript object to my Web API Controller I always get null values. Even though I have a complete object I need to specify each attribute and value as you can see below. How can I make Web API accept a ready made Javascript object and bind it correctly?</p>
  
  <p>C# Web Api Controller:</p>
  
  <pre><code>[Route("addcredentials/{salesId}")]
  [HttpPost]
  public IHttpActionResult AddCredentials([FromUri] int salesId, [FromBody] ScriveCredentials credentials)
  {
      return Ok(credentials);
  }
  </code></pre>
  
  <p>C# Credentials object:</p>
  
  <pre><code>public class Credentials
  {
      public string ClientIdentifier { get; set; }
  
      public string ClientSecret { get; set; }
  
      public string TokenIdentifier { get; set; }
  
      public string TokenSecret { get; set; }
  }
  </code></pre>
  
  <p>Javascript object passed to resource, saved as "result" further down:</p>
  
  <pre><code>{ClientIdentifier: "a", ClientSecret: "b", TokenIdentifier: "c", TokenSecret: "d"}
  </code></pre>
  
  <p>Resource method:</p>
  
  <pre><code>addCredentials: {
      method: 'POST',
      url: 'api/addcredentials/:userSalesId'
  }
  </code></pre>
  
  <p>Usage that results in null values:</p>
  
  <pre><code>userResource.addCredentials({ userSalesId: user.SalesId }, { credentials: result}).$promise.then(function (data) {
      console.log(data);
  });
  </code></pre>
  
  <p>Payload for this request:</p>
  
  <pre><code>{"credentials":{"ClientIdentifier":"a","ClientSecret":"b","TokenIdentifier":"c","TokenSecret":"d"}}
  </code></pre>
  
  <p>Usage that works but seems overly complicated:</p>
  
  <pre><code>userResource.addCredentials({ userSalesId: user.SalesId }, { ClientIdentifier: result.ClientIdentifier, ClientSecret: result.ClientSecret, TokenIdentifier: result.TokenIdentifier, TokenSecret: result.TokenSecret }).$promise.then(function (data) {
      console.log(data);
  });
  </code></pre>
  
  <p>Request payload:</p>
  
  <pre><code>{"ClientIdentifier":"a","ClientSecret":"b","TokenIdentifier":"c","TokenSecret":"d"}
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Tried the following and it did not work either, null on all values:</p>
  
  <pre><code>addScriveCredentials: {
      method: 'POST',
      url: 'api/addcredentials/'
  
  result.SalesId = user.SalesId;
  userResource.addCredentials({}, { credentials: result }).$promise.then(function (data) {
      console.log(data);
  });
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>[Route("addcredentials")]
  [HttpPost]
  public IHttpActionResult Addcredentials(Credentials credentials)
  {
      return Ok(credentials);
  }
  </code></pre>