Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

AddJsonOptions method in Startup.cs doesn't work #7741


User avatar
0
digitalcontrol created

AddJsonOptions method in Startup.cs doesn't work. We tried a few options but none of them worked. How can we set SerializerSettings.DateFormatString?

First option:

services.AddMvc(options =>
{
	options.Filters.Add(new CorsAuthorizationFilterFactory(DefaultCorsPolicyName));
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddJsonOptions(options =>
{
	options.SerializerSettings.DateFormatString = "dd-MMM-yyyy";
});

Second option from link https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2764 :

services.PostConfigure<MvcJsonOptions>(options =>
{
	foreach (var convert in options.SerializerSettings.Converters)
	{
		if (convert is AbpDateTimeConverter)
		{
			var tmpConverter = convert as AbpDateTimeConverter;
			tmpConverter.DateTimeFormat = "dd-MMM-yyyy";
		}
	}
});
return services.AddAbp<RIMIKSXWebHostModule>(options =>
{
	...
});

Third option:

services.Configure<MvcJsonOptions>(options => { options.SerializerSettings.DateFormatString = "dd-MMM-yyyy"; });
return services.AddAbp<RIMIKSXWebHostModule>(options =>
{
	...
});

2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Application Services as Controllers

    To use Mvc datetime format options, you can set this property Configuration.Modules.AbpAspNetCore().UseMvcDateTimeFormatForAppServices. Its default value is false.

  • User Avatar
    0
    digitalcontrol created

    It works! Thank you.