This is my controller's action for POST api/foo?bar=true requests:
[HttpPost]
[Route("api/foo")]
public async Task<HttpResponseMessage> Update(bool bar)
{}
It works fine, but when I try to do the same with a query parameter with no value like POST api/foo?bar, the action above doesn't work and this message is returned:
The parameters dictionary contains a null entry for parameter 'bar' of non-nullable type 'System.Boolean' for method 'System.Threading.Tasks.Task`[System.Net.Http.HttpResponseMessage] Update(Boolean)' in 'Foo.Controllers.FooController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
How can I make requests like POST api/foo?bar get into the Update() action? Optional parameter/Other type for the parameter?
Any help is welcome! Thanks.