We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Empty grid with urladaptor

Why is my grid empty when using urladaptor like this?

public IActionResult GridDatasource([FromBody]DataManagerRequest dm)
        {
            var dsRacuni = from r in _context.FirmaRacun
                           where r.FirmaId == 13
                           select r;

            IEnumerable<FirmaRacun> DataSource = dsRacuni.AsEnumerable();

            DataOperations operation = new DataOperations();
            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<FirmaRacun>().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);
        }

<ejs-grid id="Grid" locale="hr-HR" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
                            <e-data-manager url="/Maticni/Firmas/GridDatasource" updateUrl="/Maticni/Firmas/NormalUpdate" adaptor="UrlAdaptor"></e-data-manager>
                            <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
                            <e-grid-columns>
                                <e-grid-column field="RacunId" isPrimaryKey="true" headerText="RacunId" width="50"></e-grid-column>
                                <e-grid-column field="FirmaId" headerText="FirmaId" width="50"></e-grid-column>
                                <e-grid-column field="BankaId" headerText="Banka" foreignKeyValue="Naziv" dataSource="ViewBag.dsBanka" validationRules="@(new { required=true})" width="50"></e-grid-column>
                                <e-grid-column field="Iban" headerText="IBAN" validationRules="@(new { required=true})" width="50"></e-grid-column>
                                <e-grid-column field="IntBrojFirme" headerText="Int. br." width="50"></e-grid-column>
                                <e-grid-column field="Aktivan" editType="booleanedit" displayAsCheckBox="true" type="boolean" headerText="Aktivan" width="50"></e-grid-column>
                            </e-grid-columns>
                        </ejs-grid>





Thanks!
Bernard.

3 Replies

PS Pavithra Subramaniyam Syncfusion Team December 25, 2018 11:30 PM

Hi Bernard, 
 
Thanks for contacting Syncfusion support. 
 
To render the Grid data, column’s field names and the property name in the data source should be same. After that Grid will be rendered with data. Due to serialization problem, your datasource field name is changed to camel case(firmaId) and so there is a mismatch in the column’s field which is in pascal case(FirmaId). This is why you don’t have data in Grid.  
 
To overcome this serialization problem, we suggest you to add the JsonOutputFormatter options under the Startup.cs file. JsonOutputFormatter is a TextOutputFormatter for JSON content. Please refer the sample below, 
 
Startup.cs 
 
public void ConfigureServices(IServiceCollection services) 
        { 
            // Add framework services. 
            services.AddMvc().AddJsonOptions(options => 
            { 
                options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); 
            }); 
        } 
 
Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 



NB Normand Bellemare April 11, 2019 04:48 AM

Hi guys,

unfortunately, we have been facing this problem for a few days now. We also tested the solution here (above). Works well so far. Unfortunately (again) we use another framework on the server side and there the part does not work, which is responsible for Anti-Forgery, among others.
Unfortunately, at the moment we only see 2 very complex solutions:
1. For each class that is serialized as Json, set a Json property name attribute.
2. For any json serialization that requires lowerCamelCase (or whatever you want to call it), explicitly specify the ContractResolver in the serialization-settings.
But as I said: that is both very expensive.
Isn't there any way to configure Syncfusion to accept and handle UpperCamelCase (or PascalCase)?

Thanks a lot in advance for a useful hint.

Greetz
Normand


PS Pavithra Subramaniyam Syncfusion Team April 15, 2019 05:20 AM

Hi Normand, 
 
Thanks for your update. 
 
We have validated your query and this problem is the default case for ASP.Net Core behavior not related to Syncfusion. While using remote data, the Pascal case is converted into camelCase. To solve this, we need to add ContractResolver in StartUp.cs file. Please refer the below links for your reference. 
 

We have prepared a sample based on your requirement with Anti-Forgery token. You can add Anti-Forgery token in Startup.cs file as like below code example. Please find the below code example and sample for your reference. 

[StartUp.ts] 
public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddMvc().AddJsonOptions(x => { 
                x.SerializerSettings.ContractResolver = new DefaultContractResolver(); 
            }); 
            services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN"); 
        } 
... 
@Html.AntiForgeryToken() 
 
<ejs-grid id="Grid" allowPaging="true" load="onLoad" actionComplete="actionComplete" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})"> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" template="#dialogtemplate"></e-grid-editSettings> 
    <e-data-manager url="/Index?handler=DataSource" insertUrl="/Index?handler=Insert" updateUrl="/Index?handler=Update" removeUrl="/Index?handler=Delete"  adaptor="UrlAdaptor"></e-data-manager> 
    ... 
</ejs-grid> 
... 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon