Home > Mobile >  JsonOptions contains SerializerSettings
JsonOptions contains SerializerSettings

Time:11-23

jsonoptions does not contain a definiton for serializersettings

    builder.Services.AddMvc(options =>
        {
            options.Filters.Add<JsonExceptionFilter>();
            options.Filters.Add<RequireHttpsOrCloseAttribute>();
            options.Filters.Add<LinkRewritingFilter>();
        })
        .AddJsonOptions(options =>
        {
            options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
            options.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
            options.SerializerSettings.DateParseHandling = DateParseHandling.DateTimeOffset;
        });

error part

CodePudding user response:

.AddNewtonsoftJson(options =>
{
    options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
    options.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
    options.SerializerSettings.DateParseHandling = DateParseHandling.DateTimeOffset;

});

CodePudding user response:

Need to Add  "AddNewtonsoftJson" in statup.cs file

Dll NuGet: Microsoft.AspNetCore.Mvc.NewtonsoftJson


    services.AddMvc().AddNewtonsoftJson(o => 
{
    o.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});

This should work.
  • Related