Server Side
public void Post(int clientID, string name, string gender) // Currently, it is bound from querystring by default
{
Console.WriteLine(clientID);
Console.WriteLine(name);
Console.WriteLine(gender);
}
Client Side
return jQuery.ajax({
'type': 'POST',
'url': url,
'contentType': 'application/json; charset=utf-8',
'data': '{ "clientID": 123, "name": "foo", "gender": "M" }',
'dataType': 'json'
});
.NET Core Web API encourage developer to take a model for model binding. However, for me, I think it is quite annoying in some cases. i.e. I need to create a model for every POST request.
I know I can use a JsonElement with [FromBody] to contain the incoming paramerters, but after trying to manipulate with JsonElement, seems that it is not that convenient to use. (compare to JObject/JArray)
May I know if there a convenient way to get my parameters without model binder? Or can I contain the parameters with Newtonsoft's JObject? Any help would be appreciate. Thanks in advance.