Previously with .net 2.0, you can add json stuffs this way
services.AddJsonOptions(options => {
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
or
services.AddMvc().AddJsonOptions(options => {
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
I realize I can't do the same thing with .net 2.1.
I get this error:
'IServiceCollection' does not contain a definition for 'AddJsonOptions'
and the best extension method overload 'MvcJsonMvcBuilderExtensions.AddJsonOptions(IMvcBuilder, Action<MvcJsonOptions>)'
requires a receiver of type 'IMvcBuilder
Anyone have a solution?
Use
services.AddMvc().AddJsonOptions(...)
to configure it.
Above extension method can be found in Microsoft.AspNetCore.Mvc.Formatters.Json
Version 2.1.0.0
. Either include this package directly, or add one of these two Microsoft.AspNetCore.App
/ Microsoft.AspNetCore.All
.
Found the problem - you need to make sure you've got a reference to
Microsoft.AspNetCore.Mvc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With