Passing Data to server in URL Adaptor

I'm trying to pass the data from sql server using asp.net mvc however it seems the data is not passing, shown nothing even it seems right. Below is my code can anyone know what I am doing wrong or what I am missing?

Below is CSHTML code:

@{
    List<object> toolbarItems_User_MaintenanceView_DataGrid = new List<object>();
    toolbarItems_User_MaintenanceView_DataGrid.Add("Add");
    toolbarItems_User_MaintenanceView_DataGrid.Add("Edit");
    toolbarItems_User_MaintenanceView_DataGrid.Add("Delete");
  
    toolbarItems_User_MaintenanceView_DataGrid.Add("Cancel");
    toolbarItems_User_MaintenanceView_DataGrid.Add("Search");
    toolbarItems_User_MaintenanceView_DataGrid.Add("ExcelExport");
    toolbarItems_User_MaintenanceView_DataGrid.Add("ColumnChooser");

}


@(Html.EJS().Grid("User_MaintenanceView_DataGrid")
     .DataSource(dataManager =>
     {
                                     dataManager.Url(@Url.Action("UrlDatasource_User_MaintenanceView_ForGridData", "Grid"))

     .Adaptor("UrlAdaptor");
      })

     .Height("500")
     .RowHeight(28)
     .EnableHover(true)
      
     .Load("OnLoadGrid")

     .DataBound("OnDataBound_Processing")
     .RowDataBound("rowOnDataBound_Processing")
     .RowSelected("rowSelected_ToProcessing")
 
     .ActionBegin("actionBegin_User_MaintenanceView_DataGrid")
     .ActionComplete("actionComplete_User_MaintenanceView_DataGrid")

     .AllowResizing(true)
     .AllowSelection(true)


     .SelectionSettings(select => select.Type(Syncfusion.EJ2.Grids.SelectionType.Multiple).PersistSelection(true))

                .AllowTextWrap(true)
                .ShowColumnMenu(false)

                .AllowFiltering(true).FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu))
                .AllowSorting()
                //--- .SortSettings(sort => sort.Columns(cols))
                //--- .AllowRowDragAndDrop()
                //--- .FrozenRows(0).FrozenColumns(0)
                .ShowColumnChooser(true)
                .Columns(col =>
                {
                    
           
                    
col.Field("Id").HeaderText("Id").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).MinWidth("50").Width("100").MaxWidth("170").ValidationRules(new { required = false }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).IsPrimaryKey(true).Add();
                    col.Field("Firstname").HeaderText("Firstname").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).MinWidth("50").Width("200").ValidationRules(new { required = false }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).IsPrimaryKey(true).MaxWidth("250").Visible(true).Add();
                    col.Field("Lastname").HeaderText("Lastname").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).MinWidth("70").Width("100").MaxWidth("150").ValidationRules(new { required = false }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).IsPrimaryKey(true).AllowFiltering(false).Visible(true).Add();
                    col.Field("Middlename").HeaderText("Middlename").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).MinWidth("50").ValidationRules(new { required = false }).Width("70").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).IsPrimaryKey(true).MaxWidth("170").Visible(true).Add();

                })

.AllowPaging(false)

.Created("OnCreated")

.EditSettings(edit => { edit.AllowAdding(false).AllowEditing(true).AllowDeleting(false); })

.PageSettings(page => page.PageCount(2))
.Toolbar(toolbarItems_User_MaintenanceView_DataGrid)


//--- .AllowPdfExport()
.AllowExcelExport()
 
.Render()
)



And below is the controller code

public ActionResult UrlDatasource_User_MaintenanceView_ForGridData(DataManagerRequest dataManager) {
_Collection_Models objModels = new _Collection_Models(); //--- Grab model if (Session["SessionModels_Collection"] != null) { _Collection_Models objCollection_Models = Session["SessionModels_Collection"] as _Collection_Models; objModels = objCollection_Models; } IEnumerable DataSource = HMAC_UserAccount_DataInformations_view.GetGridData_User_MaintenanceView_Records(objModels); DataOperations operation = new DataOperations(); List str = new List(); if (dataManager.Search != null && dataManager.Search.Count > 0) { DataSource = operation.PerformSearching(DataSource, dataManager.Search); //--- Search } if (dataManager.Sorted != null && dataManager.Sorted.Count > 0) //--- Sortings { DataSource = operation.PerformSorting(DataSource, dataManager.Sorted); } if (dataManager.Where != null && dataManager.Where.Count > 0) //--- Filtering { DataSource = operation.PerformFiltering(DataSource, dataManager.Where, dataManager.Where[0].Operator); } int count = DataSource.Cast().Count(); if (dataManager.Skip != 0) { DataSource = operation.PerformSkip(DataSource, dataManager.Skip); //--- Paging } if (dataManager.Take != 0) { DataSource = operation.PerformTake(DataSource, dataManager.Take); } return Get_JsonDataResult(dataManager, DataSource, count); }

1 Reply

RS Rajapandiyan Settu Syncfusion Team December 15, 2021 02:55 PM UTC

Hi Rica, 

Thanks for contacting Syncfusion support. 

When using URL Adaptor in EJ2 Grid, we need to return the data with result and count values in object format. Then only the data are loaded properly in Grid. This is explained detailly in the below documentation.  
  
UrlAdaptor:  
 
KB:  
 
 
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm) 
{ 
    IEnumerable DataSource = OrdersDetails.GetAllRecords().ToList(); 
     // perform the actions here 
    ----    
    // return the data based on RequiresCount 
    return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource); 
} 
 
 
Kindly ensure that the returned data is in result and count format or not. 
 
Screenshot: 
 
 
 
Still, if you face the same issue, kindly share the below details to validate further. 

  1. Share the response from the server in the NetworkTab.
  2. Bind the actionFailure event in Grid and let us know if you face any exceptions or errors in that event.
 

    function actionFailure(args) { 
        console.log(args); 
    } 


  1. Share the console error if any.
  2. Share the video demo of the reported problem and the Grid script version.
  3. If possible share a simple issue reproducible sample which will be very helpful to provide a solution at earlier.

Regards, 
Rajapandiyan S 


Loader.
Up arrow icon