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?
10 Answers, 1 is accepted

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
}
});
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

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



I was able to find a "fix" but the default should still accept camelCase as the default. But incase anyone runs in to this and cant convert their entire app over. Just set the .From property on the field in the Model.
.Model(m =>
{
m.Id(x => x.Id);
m.Field(x => x.Name).From("name");
m.Field(x => x.Surname).From("surname");
m.Field(x => x.IsActive).From("isActive");
}))

Here is a work around if people need since telerik didn't offer it up by default for some reason. I would still expect the camelCase to be the default though.
.Model(m =>
{
m.Id(x => x.Id);
m.Field(x => x.Name).From(
"name"
);
m.Field(x => x.Surname).From(
"surname"
);
m.Field(x => x.IsActive).From(
"isActive"
);
}))

This workaround is not working for me. (the one with From)
How can I specify the correct names?
I cannot change the JSON serializer, will impact all the application.
The From option in the Model definition can be used when DataSource is specified as Custom. The example below shows how custom DataSource can be used with the Grid widget.
Regards,
Viktor Tachev
Progress Telerik