AddMvc
returns an IMvcBuilder
implementation, which has a corresponding AddJsonOptions
extension method. The new-style methods AddControllers
, AddControllersWithViews
, and AddRazorPages
also return an IMvcBuilder
implementation. Chain with these in the same way you would chain with AddMvc
:
services.AddControllers()
.AddJsonOptions(options =>
{
// ...
});
Note that options
here is no longer for Json.NET, but for the newer System.Text.Json
APIs. If you still want to use Json.NET, see tymtam's answer
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…