Sunday, November 19, 2017

How do I turn off the Pascal case to camel case effect in handing objects back from MVC controllers in a .NET Core application?

I attended a tech talk on this once, and, yes: It's not a bug. It's a feature.

services.AddMvc();

 
 

...in Startup.cs should be replaced with the following, expanded line of code to fix the feature per this.

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

 
 

This is what it is assuming that JavaScript should idiomatically have names in camel case while C# POCOs should idiomatically have names in Pascal Case. However, you don't want camel case names at TypeScript objects.

No comments:

Post a Comment