From .NET Core I return object in Ok() in method with IActionResult result:
public async Task<IActionResult> UploadJsonFiles()
{
return Ok(new { status = "Ok", message = "" });
}
In Angular I have that json but it is formatted as string. I don't have object with property status and message, only string:
this.uploader.response.subscribe(res => {
..
res = "{"status":"Ok","message":""}"
In Startup I have set formatters for controllers:
services.AddControllersWithViews().AddNewtonsoftJson();
services.AddControllers(options =>
{
options.RespectBrowserAcceptHeader = true; // false by default
})
.AddJsonOptions(options =>
options.JsonSerializerOptions.PropertyNamingPolicy = null);
acceptheader in your request. It should sayapplication/json. Take a look atContent-Typeheader in the response. It should also sayapplication/json[Produces("application/json")]attribute on the method.return Json(new { status = "Ok", message = "saaaaaa" });and try again.