Data Binding

21 Dec 20223 minutes to read

The Grid uses DataManager, which supports both RESTful JSON data services binding and local JavaScript object array binding. The DataSource property can be assigned either with the instance of DataManager or JavaScript object array collection.

It supports the following kinds of data binding method:

  • List binding
  • DataTable binding
  • Remote data

Sending additional parameters to the server

To add a custom parameter to the data request, use the addParams method of Query class. Assign the Query object with additional parameters to the grid Query property.

@Html.EJS().Grid("Params").DataSource(dataManger =>

}).Query("new'ej2Grid', 'true')").Columns(col =>
    col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
    col.Field("CustomerID").HeaderText("Customer ID").Width("160").Add();
    col.Field("EmployeeID").HeaderText("Employee ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
    col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add();

public IActionResult Index()
    return View();


The parameters added using the Query property will be sent along with the data request for every grid action.

Handling HTTP error

During server interaction from the grid, some server-side exceptions may occur, and you can acquire those error messages or exception details in client-side using the ActionFailure event.

The argument passed to the ActionFailure event contains the error details returned from the server.

@Html.EJS().Grid("check").DataSource(dataManger =>

}).Columns(col =>
   col.Field("ProductID").HeaderText("Product ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
   col.Field("ProductName").HeaderText("Product Name").Width("150").Add();
   col.Field("UnitPrice").HeaderText("Supplier ID").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();


    function actionFailure(args) {
        var span = document.createElement('span');
        this.element.parentNode.insertBefore(span, this.element); = '#FF0000'
        span.innerHTML = 'Server exception: 404 Not found';
public IActionResult Index()
    return View();


The ActionFailure event will be triggered not only for the server errors, but also when there is an exception while processing the grid actions.

Binding with ajax

You can use Grid DataSource property to bind the datasource to Grid from external ajax request. In the below code we have fetched the datasource from the server with the help of ajax request and provided that to DataSource property by using onSuccess event of the ajax.

<script type="text/javascript">
    var grid = document.getElementById('Grid').ej2_instances[0]; // Grid instance
    var ajax = new ej.base.Ajax('/Home/UrlDatasource', 'GET');
    ajax.onSuccess = function (data) {
        grid.dataSource = JSON.parse(data).result;


  • If you bind the dataSource from this way, then it acts like a local dataSource. So you cannot perform any server side crud actions.

Troubleshoot: Grid render rows without data

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.

public void ConfigureServices(IServiceCollection services)
    services.AddMvc().AddJsonOptions(options =>
        options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();

See Also