JSON serialization settings in asp-prerender-data tag helper

181 views Asked by At

In my asp.net core 2.1 web application I want to change the way server serializes JSON responses. I wanted to serialize property names as they are (not in camlCase or PascalCase). To achieve this serialization for mvc controller results I did this:

services.AddMvc().AddJsonOptions(opts =>
     opts.SerializerSettings.ContractResolver = new DefaultContractResolver())

Now my controllers return JSON as I intended to.

But my application is a Single Page React application that uses Server Side rendering with the spa-services. Every time a user navigates to a route using either the browser's address bar, by refreshing the page or by an external link, the server sends pre-rendered html with additional data using the asp-prerender-data helper.

It seems spa services don't use the same JSON serializer settings with the MVC controllers, and my initial page data are send to client in camlCase and this breaks rendering.

How can I set DefaultContractResolver for the asp-prerender-data helper too?

0

There are 0 answers