Json Serialization Breaks Grid

6 posts, 0 answers
  1. AP
    AP avatar
    187 posts
    Member since:
    Apr 2010

    Posted 04 Oct Link to this post

    I've just set up a grid using ASP.NET core, and the controller method to return data is called, but no data is displayed by the grid. Looking at the JSON returned  in Fiddler, it seems the field name cases have been changed by the serializer to be camel case, with the first letter always being lower case.

     

    As the field names of the table are uppercase, this means they aren't being picked up by the grid. The only other option is to serialize as snake case, which doesn't help.

    How can this be handled?

  2. AP
    AP avatar
    187 posts
    Member since:
    Apr 2010

    Posted 04 Oct Link to this post

    After a bit of searching I found a post explaining how to turn this behaviour off.

    Add this to the Startup.cs file:-

    services.AddMvc()
                  .AddJsonOptions(opt =>
                  {
                      var resolver = opt.SerializerSettings.ContractResolver;
                      if (resolver != null)
                      {
                          var res = resolver as DefaultContractResolver;
                          res.NamingStrategy = null// <<!-- this removes the camelcasing
                      }
                  });

  3. Telerik UI for ASP.NET Core is out
  4. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 06 Oct Link to this post

    Hi,

    Indeed the properties are serialized in camel case to the client by default. This was a breaking change that was introduced before the final release of MVC Core.


    In order to revert the behavior you need to modify the settings in the ConfigureServices method as you have done. This is also described in the documentation. Please note Step 4 in the article below:



    Regards,
    Viktor Tachev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. AP
    AP avatar
    187 posts
    Member since:
    Apr 2010

    Posted 06 Oct in reply to Viktor Tachev Link to this post

    OK. I missed that, as the explanation just says to add services.AddKendo() at the end. The documentation could do with explaining the other entry, and what it does. 
  6. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 07 Oct Link to this post

    Hi,

    Thank you for the feedback. Currently the issue is shown only in the comments in the code snippet. However, we will consider updating the description in a way that it is more clear what is the purpose of the added code.


    Regards,
    Viktor Tachev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Francis
    Francis avatar
    1 posts
    Member since:
    Feb 2011

    Posted 13 Oct in reply to AP Link to this post

    Thanks AP. Digging my head as to why the grid was empty for a while.
Back to Top
Telerik UI for ASP.NET Core is out