URL Adapter in .NET Core 6 MVC

Hi,


the URL Adapter is not working as expected with the demo and docs. 

List Binding is working just fine but the Data is not shown with URL-Adapter:


Here is the Function:


public ActionResult Get(DataManagerRequest dm)

        {

            IEnumerable DataSource = _context.Movie.ToList();

            DataOperations operation = new DataOperations();

            List<string> str = new List<string>();

            if (dm.Search != null && dm.Search.Count > 0)

            {

                DataSource = operation.PerformSearching(DataSource, dm.Search); //Search

            }

            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting

            {

                DataSource = operation.PerformSorting(DataSource, dm.Sorted);

            }

            if (dm.Where != null && dm.Where.Count > 0) //Filtering

            {

                DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);

            }

            int count = DataSource.Cast<Movie>().Count();

            if (dm.Skip != 0)

            {

                DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging

            }

            if (dm.Take != 0)

            {

                DataSource = operation.PerformTake(DataSource, dm.Take);

            }

            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);

        }


I remember that i used to have some settings regarding JSON in my StartUp.CS


Do you have an working example for .NET Core 6 MVC?


Best regards!


5 Replies

SK Sujith Kumar Rajkumar Syncfusion Team February 2, 2022 11:05 AM UTC

Hi Mark, 
 
Greetings from Syncfusion support. 
 
From the provided information we suspect that you might be facing serialization problem in the ASP.NET Core where it returns the JSON results in camelCase format by default, because of which the data source field names would be returned in camelCase whereas the columns fields are in PascelCase. And since the column field names are case-sensitive the data will not be displayed in the Grid. 
 
This is a general issue in the Core platform and you can resolve this problem by serializing and returning them in the PascelCase format using the below code in the startup.cs file of the application, 
 
More details on this issue can be checked in the below stack overflow links, 
 
 
So for ASP.NET CORE version greater than 5.X add the below code in startup.cs file to resolve the problem, 
 
 
public void ConfigureServices(IServiceCollection services) 
{ 
         ... 
    services.AddMvc().AddJsonOptions(o => 
    { 
        o.JsonSerializerOptions.PropertyNamingPolicy = null; 
       o.JsonSerializerOptions.DictionaryKeyPolicy = null; 
    }); 
} 
 
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 



MH Mark Heidl February 2, 2022 12:03 PM UTC

Hi Sujith,


This is the reply from the function:

[{"Id":1,"Title":"When Harry Met Sally","ReleaseDate":"1989-02-12T00:00:00","Genre":"Romantic Comedy","Price":1700.00},{"Id":2,"Title":"Ghostbusters ","ReleaseDate":"1984-03-13T00:00:00","Genre":"Comedy","Price":8.99},{"Id":3,"Title":"Ghostbusters 2","ReleaseDate":"1986-02-23T00:00:00","Genre":"Comedy","Price":9.99},{"Id":4,"Title":"Rio Bravo","ReleaseDate":"1959-04-15T00:00:00","Genre":"Western","Price":3.99}]

Looks like PascalCase for me. But the Grid is still not working.


FYI: .Net Core 6 does not have a Startup.CS anymore. But i could do the configuration within the Program.cs


builder.Services.AddMvc().AddJsonOptions(o =>

{

o.JsonSerializerOptions.PropertyNamingPolicy = null;

o.JsonSerializerOptions.DictionaryKeyPolicy = null;

});


But that didnt help here :(



Maybe this can help you?


Best regards,

Mark



PS Pavithra Subramaniyam Syncfusion Team February 3, 2022 09:32 AM UTC

Hi Mark, 
 
We have tried to reproduce the issue with .net6 core sample but the Grid is working fine at our side. We also have prepared a sample for your reference which can be downloaded from the below link 
 
 
So could you share the below details that will be helpful for us to provide a better solution as early as possible. 
 
  1. Bind “actionFailure” event to the Grid and share the argument details if the event got triggered
  2. Share the Grid code details to check whether the issue with Grid settings
  3. Share the Syncfusion package version
 
Regards, 
Pavithra S 



MH Mark Heidl February 3, 2022 10:13 AM UTC

Hi Pavithra,


After i did everything the same way you did i finally saw that your request Required the count and mine didnt 


->


public ActionResult Get([FromBody] DataManagerRequest dm)


The [FromBody] was the missing part! After i added this - its working now.


Thanks and best regards,

Mar



VN Vignesh Natarajan Syncfusion Team February 4, 2022 04:13 AM UTC

Hi Mark,  
 
Thanks for the update.  
 
We are glad to hear that you have resolved your query.  
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon