[HttpPost, Route("foo")]
public void DoStuff(FooModel args)
{
if(args == null) args = new FooModel();
}
public class FooModel
{
public string Foo { get; set; }
public string Bar { get; set; }
}
When a POST request is sent to the Web API method, and the HTTP request does not contain any arguments that would fill the model, instead of passing the empty model into action, the Web API instead simply passes null to the action, requiring a null check against the model argument at the beginning of each action.
I understand that a structure is probably trying to avoid an unnecessary object construct, but these are always lightweight classes without any specific function. This will save time and become more consistent if the model were built every time, and did not try to save some insignificant fraction of a millisecond, which would be worth just building a model object in any case and passing it to action.
( ) , ?
ASP.Net Web API 2.2.