- Home
- Forum
- ASP.NET Core - EJ 2
- UrlAdaptor in MVC or/and in Razor Pages
UrlAdaptor in MVC or/and in Razor Pages
Hi,
Have you some samples - in the last version of EJ2 - with UrlAdaptor and MVC and with UrlAdaptor and Razor Pages.
I found some old samples and if I can obtain data in MVC, I do not in Razor Pages (it goes in the handler function - which returns data like in the MVC controller - but grid does not show anything). And I also can't manage an update. I go through the action of the controller but I do not receive data set by the action "update".
I'm on .NET CORE 3.1 on 2 projets. One in MVC and the other in Razor Pages. And I use your excellent products in version 18.1.0.44.
I suspect, eventually, a problem with System.Json.Text and NewtonSoft.Json (probably at CamelCase level).
Best regards
SIGN IN To post a reply.
3 Replies
FF
Frederic FOURGEOT
April 21, 2020 08:08 AM UTC
I fixed my mistake in MVC solution. I forgot the FromBody attribute in my update method.




But I've always a problem with the Razor Pages solution. My grid is empty with two lines space.
Anti forgery service
Json result from Items handler in Entite
FF
Frederic FOURGEOT
April 21, 2020 02:06 PM UTC
Problem comes from a line of code in the ConfigureServices method in Startup.cs

options.JsonSerializerOptions.ReferenceHandling = ReferenceHandling.Preserve;
I'm using a preview version of System.Json.Text which has an option to manage loops during serialization process. In this preview new properties added : $id, $ref, etc. I think these properties are problematic. If I delete this line of code, I get the data normally.
Solution ?
Use NewtonsoftJson in place of System.Json.Text. I've added the Microsoft.AspNetCore.Mvc.NewtonsoftJson nuget package in my project, and change the ConfigureServices method in Startup.cs like this :
And... voilà ! I've data in my grid :) !!!
RS
Rajapandiyan Settu
Syncfusion Team
April 21, 2020 04:58 PM UTC
Hi Frederic,
Greetings from syncfusion support.
Query : UrlAdaptor in MVC or/and in Razor Pages
In ASP.NET Core, by default the JSON results are returned in camelCase format. So grid field names are also changed in camelCase.
To avoid this problem, you need to add DefaultContractResolver in Startup.cs file.
If the ASP.NET CORE version is 2.X then add the below code in startup.cs file
|
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
});
}
|
If the ASP.NET CORE version is 3.X then add the below code in startup.cs file
|
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver =
new DefaultContractResolver());
}
}
|
Please get back to us if you need further assistance on this.
Regards,
Rajapandiyan S
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
FF Frederic FOURGEOT
- Apr 21, 2020 01:18 AM UTC
- Apr 21, 2020 04:58 PM UTC