This is a migrated thread and some comments may be shown as answers.

Json Result can't be binded to KendoUI grid

5 Answers 319 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 16 May 2017, 07:05 PM
I can't display in a kendo grid the data that I am returning from my Controller as Json Result.


     
  [HttpPost]
  public ActionResult PermitSearch(BptSearchViewModel viewModel)
  {
    var data = appService.SearchPermitInspection(viewModel);
 return Json(data, JsonRequestBehavior.AllowGet);<br>        }


now from my View I am submitting the information using ajax

      @using (Ajax.BeginForm("PermitSearch", "Home", null, new AjaxOptions
      {
            HttpMethod = "post",
            InsertionMode = InsertionMode.InsertAfter,
            UpdateTargetId = "search-results-grid",
            OnComplete = "OnCompleteMethod"
      }))
      {
               ....
      }

    <div id="search-results-grid"></div>

an the script with the OnCompleteMethod is below

    function OnCompleteMethod(dataq, status) {
        if (status === "success") {
            $("#search-results-grid").kendoGrid({
                columns: [
                    {
                        field: "jobname",
                        title: "Job Type"
                    }
                dataSource: {
                    data: {
                        "items" : dataq
                    },
                    schema: {
                        data: "items"
                    }
                },
                groupable: true,
                sortable: true,
                pageable: {
                    refresh: true,
                    pageSizes: true,
                    buttonCount: 5
                },
                noRecords: {
                    template: "No data available on current page. Current page is: #=this.dataSource.page()#"
                }
            });
        }
    }
 
and the data that I am returning looks like this after I call the controller

    [
      {
        "jobname": "job1"
      },
      {
        "jobname": "job2"
      }
    ]

What I am doing wrong here?

5 Answers, 1 is accepted

Sort by
0
Alain
Top achievements
Rank 1
answered on 17 May 2017, 01:13 PM

HI Ivan,

Here there is an example how to bind a grid to local data:

http://demos.telerik.com/kendo-ui/grid/local-data-binding

Maybe it can help you

Alain

0
Ivan
Top achievements
Rank 1
answered on 17 May 2017, 01:41 PM

I just added the schema but it doesn't work for me.I don't know why this example is working http://dojo.telerik.com/UtOQE/3 but when I pass the data from my Controller returning the Json instead of copying the data as part of the javascript it doesn't work

 

0
Ivan
Top achievements
Rank 1
answered on 17 May 2017, 01:43 PM

I tried to add the schema as well, but it did not work. I don't know why this example is working http://dojo.telerik.com/UtOQE/3 

but when I pass the data from my controller as JsonResult it doesn't work

0
Ivan
Top achievements
Rank 1
answered on 17 May 2017, 04:13 PM

Finnaly I solved my problem on this way, I was returning the full response

dataSource: {
                    data: JSON.parse(dataq.responseText),
                }

 

0
Viktor Tachev
Telerik team
answered on 18 May 2017, 01:23 PM
Hello Ivan,

Please check out the answer in the other thread you have submitted. Give the suggested approach a try and see how it works for you. In case you have additional queries please use only one of the threads.



Regards,
Viktor Tachev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Ivan
Top achievements
Rank 1
Answers by
Alain
Top achievements
Rank 1
Ivan
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or