title: Web Api - How to return a dynamic object with 201 status code
body: <p>I'm trying to return the recently added entity Id in a Web Api action method as a JSON. Example:</p>
  
  <pre><code>{ bookId = 666 }
  </code></pre>
  
  <p>The Controller Action code is as follows:</p>
  
  <pre><code>[HttpPost, Route("")]
  public HttpResponseMessage Add(dynamic inputs)
  {
      int bookId = bookService.Add(userId, title);
  
      dynamic book = new ExpandoObject();
      book.bookId = bookId
  
      return new HttpResponseMessage(HttpStatusCode.Created)
      {
          Content = new ObjectContent&lt;dynamic&gt;(book,
              new JsonMediaTypeFormatter
              {
                  UseDataContractJsonSerializer = true
              })
      };
  }
  </code></pre>
  
  <p>The problem here is to accomplish it returning a dynamic content (without Dto) and returning the HttpStatusCode.Created (201 http status).</p>
  
  <p>Now I have the next error:</p>
  
  <blockquote>
    <p>{"Message":"An error has occurred.","ExceptionMessage":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.","ExceptionType":"System.InvalidOperationException","StackTrace":null,"InnerException":{"Message":"An error has occurred.","ExceptionMessage":"No se espera el tipo 'System.Dynamic.ExpandoObject' ...</p>
  </blockquote>
  
  <p>if I change the <code>new ObjectContent&lt;dynamic&gt;</code> by <code>new ObjectContent&lt;ExpandoObject&gt;</code> I get the correct 201 status header response, but the JSON result is as as follows:</p>
  
  <pre><code>[{"Key":"bookId","Value":666}]
  </code></pre>
  
  <p>So, is it possible to return { bookId: 666} using dynamics (not Dtos) setting the header status code to 201 (Created)?</p>
  
  <p>Thank you for your help.</p>