0

Is there a way to disable camel case serialization for a specific controller or action in asp.net core? I'm aware it can be set across all controllers in the Startup file with something like this:

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

but that's not what I'm looking for.

I'm looking for something like a custom attribute solution like this: https://stackoverflow.com/a/32912081/2788283 but for .net core.

Any help would be greatly appreciated. Thank you.

Tseng
  • 61,549
  • 15
  • 193
  • 205
mikelt21
  • 2,728
  • 4
  • 23
  • 33

1 Answers1

2

You can use the Json helper method, which accepts a JsonSerializerSettings as second parameter

public IActionResult Get() 
{
    return Json(new { Value = "Test" }, new JsonSerializerSettings
    {
        ... 
    });
}
Tseng
  • 61,549
  • 15
  • 193
  • 205