public class WebApiController : UmbracoApiController
{
// ~/Umbraco/Api/WebApi/CreateUser/
public IEnumerable<WebApiCreateUser> CreateUser([FromBody] string JsonData)
{
// JsonData is allways NULL why? Have do I get the json string?
List<WebApiCreateUser> ls = new List<WebApiCreateUser>();
ls.Add(new WebApiCreateUser() { Message = "Succes" });
return ls;
} }
I'm not sure, but maybe the [FromBody] parameter needs to be a complex type compatible with the json passed from the client? I think ASP.NET Web Api will try to convert the json for you before your CreateUser method is called.
So maybe create a private User class with FirstName and LastName properties and use that class as the type of the parameter.
Otherwise, look at the client side, and what the json string looks like after you've done the JObject.ToString() and see if there are any surprises there.
[FromBody] return allways Null in Umbraco API controller
When I upload a string (json) to the API I allways get Null.
Client:
API:
Thanks for any help :-)
I'm not sure, but maybe the [FromBody] parameter needs to be a complex type compatible with the json passed from the client? I think ASP.NET Web Api will try to convert the json for you before your CreateUser method is called.
https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api
So maybe create a private User class with FirstName and LastName properties and use that class as the type of the parameter.
Otherwise, look at the client side, and what the json string looks like after you've done the JObject.ToString() and see if there are any surprises there.
-Tor
Hi Lars
Does it work if you either define the parameter as
dynamic
as in this example https://stackoverflow.com/a/23135783/1693918 or prefix the posted value with=
as in these examples? https://stackoverflow.com/a/11666985/1693918 https://stackoverflow.com/a/23135629/1693918You could also try creating a class with properties matching the json data:
/Bjarne
is working on a reply...