title: Binding single value from the body of a POST with MVC
body: <p>I am implementing a protocol in ASP.NET MVC, and I need to be able to bind data from a request made like this:</p>
  
  <pre><code>curl -H "Content-Type: application/json" -d 'true' http://example.com/operation/some_id
  </code></pre>
  
  <p>I have tried using the <code>[FromBody]</code> attribute on the parameter in my controller, like this:</p>
  
  <pre><code>public ActionResult Operation(string id, [FromBody] bool setSomething)
  </code></pre>
  
  <p>The above code does not work, as it throws an exception when MVC attempts to set <code>setSomething</code> to <code>null</code>.  If I change <code>setSomething</code> to a string, it always gets set to <code>null</code>, so I am unable to parse it to a bool in the action.</p>
  
  <p>I don't have the luxury of changing <code>'true'</code> to <code>'=true'</code> as I have read elsewhere when similar questions were asked.  The POST generated from the curl command above is set in stone.  What I need is some way of taking the value <code>true</code> (which is valid json, even without a key) from the body of the POST and assigning it to <code>setSomething</code>.  I also need to do this in a way that doesn't prevent me from assigning <code>some_id</code> to <code>id</code>, as I already have working with a custom route.</p>
  
  <p>Does anyone know how this can be accomplished in MVC or Web API?</p>
  
  <p>Any help is appreciated.</p>