The standard way AFAIK to return data in ASP.NET Core Web Api is by using IActionResult
and providing e.g. an OkObject
result. This works fine with
And of course a few minutes after posting the question I stumble upon a solution :)
Just return Content
with the content type application/json
...
return Content("{ \"name\":\"John\", \"age\":31, \"city\":\"New York\" }", "application/json");
In your action, replace Ok()
with the Content()
method, which lets you set the content (raw content), content type, and status code of your response: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.contentresult?view=aspnetcore-2.0