Skip to content

Commit 8fedd0b

Browse files
alestoyaDimitar-Goshev
authored andcommitted
fix: reports are not loaded telerik/kendo#22622
1 parent 2b926fc commit 8fedd0b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.AspNetCore.Mvc.Filters;
2+
using Microsoft.AspNetCore.Mvc.Formatters;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Newtonsoft.Json.Serialization;
5+
using Newtonsoft.Json;
6+
using System.Buffers;
7+
8+
namespace Web.Attributes
9+
{
10+
public class JsonConfigFilterAttribute : ActionFilterAttribute
11+
{
12+
public override void OnResultExecuting(ResultExecutingContext context)
13+
{
14+
if (context.Result is ObjectResult objectResult)
15+
{
16+
var serializerSettings = new JsonSerializerSettings
17+
{
18+
NullValueHandling = NullValueHandling.Include,
19+
DateTimeZoneHandling = DateTimeZoneHandling.Unspecified,
20+
ContractResolver = new CamelCasePropertyNamesContractResolver()
21+
};
22+
23+
var jsonOutputFormatter = new NewtonsoftJsonOutputFormatter(
24+
serializerSettings,
25+
ArrayPool<char>.Shared,
26+
new MvcOptions { },
27+
new MvcNewtonsoftJsonOptions()
28+
);
29+
30+
objectResult.Formatters.Add(jsonOutputFormatter);
31+
}
32+
33+
base.OnResultExecuting(context);
34+
}
35+
}
36+
}

EShop/Web/Controllers/ReportsController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ namespace Web.Controllers
55
using Microsoft.AspNetCore.Mvc;
66
using System.Net.Mail;
77
using System.Net;
8+
using Web.Attributes;
89

910
[Route("api/reports")]
11+
[JsonConfigFilter]
1012
public class ReportsController : ReportsControllerBase
1113
{
1214
public ReportsController(IReportServiceConfiguration reportServiceConfiguration)

0 commit comments

Comments
 (0)