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