I have a RESTful web service, built with ASP.NET WebAPI 2.
I have this method in a controller:
[Route("{DocNum:int}")]
public object Patch(int DocNum, string str = null)
{
if(str == null)
{
//do something when parameter has NOT been passed...
}
else
{
//do something when parameter has been passed...
}
}
If I don't pass str, it is null in the method.
If I pass str=abc, it is "abc" in the method.
If I pass str= (empty string), it is null in the method.
That is ASP.NET WebAPI 2 treats empty string query parameters as null!
It seems it is by design, but is there a way to treat an empty string as an empty string?