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

Issue with Data Manager not calling WebAPI

Here is my code on home.component.ts -
import { Component, OnInit, ViewChild } from '@angular/core';
import { DataManager, Query, UrlAdaptor, WebApiAdaptor, ODataAdaptor } from '@syncfusion/ej2-data';
import { GridComponent, EditService, ToolbarService, PageService, ColumnChooserService, EditSettingsModel, ToolbarItems } from '@syncfusion/ej2-ng-grids';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  providers: [ToolbarService, EditService, PageService, ColumnChooserService]
})
export class HomeComponent implements OnInit {

  public title: string = "Manage Client Payment Options";
  public data: Object[];
  public dataManager: DataManager;
  @ViewChild('grid')
  public grid: GridComponent;
  public editSettings: EditSettingsModel;
  public toolbar: ToolbarItems[];
  public pageSettings: Object;
  ngOnInit(): void {
    console.log("This is testing");
    this.dataManager = new DataManager({
      //url: '/api/Payment',
      url: '/api/Payment',
      adaptor: new WebApiAdaptor
    });
    this.editSettings = { allowEditing: true, allowAdding: false, allowDeleting: false, mode: 'Normal' };
    this.toolbar = ['Edit', 'Update', 'Cancel', 'ColumnChooser'];
    //this.pageSettings = { pageCount: 5 };


  }
}

Here is my Web API Code -
[HttpGet()]
        public ActionResult Get()
        {
            List<ClientInfo> clientPaymentInfos = new List<ClientInfo>();
            Int32 intCnt = 0 ;
            DataTable dtPaymentInfo = new DataTable();
            using (SqlConnection conn = new SqlConnection(_connString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "pr_GetAllClientInfo";
                    SqlDataReader dr = cmd.ExecuteReader();
                    dtPaymentInfo.Load(dr);
                    intCnt = dtPaymentInfo.Rows.Count;
                    foreach(DataRow dRow in dtPaymentInfo.Rows)
                    {
                        ClientInfo clientInfo = new ClientInfo();
                        clientInfo.clientNumber = dRow["ClientNumber"].ToString();
                        clientInfo.clientName = dRow["ClientName"].ToString();
                        clientInfo.relatedClientNumber = dRow["RelatedClientNumber"].ToString();
                        clientInfo.allowACHProcessing = (Boolean)dRow["AllowACHProcessing"];
                        clientInfo.allowCCProcessing = (Boolean)dRow["AllowCCProcessing"];
                        clientPaymentInfos.Add(clientInfo);
                    }
                }
            }
            var result = new { count = intCnt, result = clientPaymentInfos };
            return Ok(result);
        }

But whenever I try to run and check the browser it does not call the Web API at all. If I try it separately it does work but cannot call from the data manager. But I get the following error -
core.js:1448 ERROR TypeError: Cannot read property 'length' of undefined
    at WebApiAdaptor.UrlAdaptor.getRequestQuery (adaptors.js:474)
    at WebApiAdaptor.UrlAdaptor.processQuery (adaptors.js:435)
    at DataManager.executeLocal (manager.js:116)
    at eval (manager.js:164)
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4736)
    at ZoneDelegate.invokeTask (zone.js:420)
    at Zone.runTask (zone.js:188)
    at ZoneTask.invokeTask (zone.js:496)
    at ZoneTask.invoke (zone.js:485)
defaultErrorLogger @ core.js:1448

Any help is greatly appreciated. My old projects still work. Not sure what the new version of .NET core is having issues.

1 Reply

VA Venkatesh Ayothi Raman Syncfusion Team November 9, 2018 06:08 AM UTC

Hi Ameet, 
 
Thanks for using Syncfusion products. 
 
We have tried to reproduce the issue at our end with latest Essential JavaScript 2 version but it is unsuccessful. We have prepared a simple sample based on your code example. Please refer to the below sample link. 


Could you please share the below details that will be helpful for us to provide a better solution as early as possible. 
  1. Share your Essential JavaScript 2 Version and ASP.NET CORE version.
  2. Share your Grid html code.
  3. Please check issue with latest Essential JavaScript 2 Version
  4. Could you please check whether the issue is due to serialization problem in your CORE application . If yes you can overcome this serialization problem[camel case] by adding 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(); 
            }); 
        } 
 
  1. Please reproduce the issue in the above sample if possible.

Regards, 
Venkatesh Ayothiraman. 


Loader.
Live Chat Icon For mobile
Up arrow icon