From 72965cfbb2b44cc6b06c1a04ec91123d8539affc Mon Sep 17 00:00:00 2001 From: Pavel Vesely Date: Wed, 15 Apr 2020 12:34:43 +0200 Subject: [PATCH] Return JSON null instead of 204 stantus from controller Services GET returns null instead of exception :) --- Oqtane.Server/Startup.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index 77768609..a5dfe59b 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -41,7 +42,12 @@ namespace Oqtane // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - services.AddMvc().AddNewtonsoftJson(); + services.AddMvc(opt => + { + // remove formatter that turns nulls into 204 - No Content responses + // sends JSON null instead + opt.OutputFormatters.RemoveType(); + }).AddNewtonsoftJson(); services.AddServerSideBlazor(); // setup HttpClient for server side in a client side compatible fashion ( with auth cookie )