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.

1 Answer 1

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

public IActionResult Get() 
{
    return Json(new { Value = "Test" }, new JsonSerializerSettings
    {
        ... 
    });
}