1

In my MVC 5.2.7 project targeting .NET framework 4.6.1, I need to set the Json serializer settings to always to use came case.

So, I want to write in the Application_Start event something like:

HttpConfiguration config = GlobalConfiguration.Configuration;
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
            new CamelCasePropertyNamesContractResolver();

Thing is: neither of the two HttpConfiguration nor the GlobalConfiguration classes are present in the MVC project.

I know that I can install the Web API related packages to get to these classes. The packages are:

1. Microsoft.AspNet.WebApi.Core; and
2. Microsoft.AspNet.WebApi.WebHost

But my question is: is there a native object inside MVC that gives me access to the Formatters collection without having to install these packages?

Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
  • Did you already try the Filter provided in answer of [this question](https://stackoverflow.com/questions/36983350/specific-json-settings-per-controller-on-asp-net-mvc-6) ? – Manoj Choudhari Oct 29 '19 at 15:01
  • @ManojChoudhari Please correct me if I am wrong but those components (ResourceExecutingContext, IResourceFilter, and the namespaces Microsoft.AspNet..) are in the .NET Core assemblies. I am talking about the .NET framework assemblies for ASP.NET MVC. – Water Cooler v2 Oct 29 '19 at 15:21

0 Answers0