6

When you have an MVC application you can append services.AddMvc().AddJsonOptions(options => ... and that will set the Json options for all the controllers.

What is the equivalent for a Blazor Server App? I tried services.AddRazorPages().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNameCaseInsensitive = true); and while the compiler didn't complain it didn't seem to have the desired effect and i still have to do the following to deserialize correctly:

var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
var list = await JsonSerializer.DeserializeAsync<IEnumerable<CustomerSearchResultDto>>(await response.Content.ReadAsStreamAsync(), options);

Any ideas? Thanks in advance.

Cef
  • 661
  • 1
  • 6
  • 26
  • Did you ever find out? – sw1337 Oct 18 '20 at 01:19
  • There appears to be an open issue for this https://github.com/dotnet/aspnetcore/issues/26000, in my current project we've just created a service for all JSON formatting. We handle the options from there to make it uniform – Victor Procure Jun 14 '21 at 21:59

0 Answers0