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

MVC 5 Grid not showing data

1 Answer 677 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shuja
Top achievements
Rank 1
Shuja asked on 16 Dec 2014, 10:27 AM
Hi,

I've created a simple MVC 5 project with a Kendo grid to display a few records from a remote server. When i run the application, the kendo grid appears but displays no records. 
I checked Fiddler and found no errors or circular references. Furthermore, the JSON output shows the correct data in it but its simply not displaying in the grid. Here is the grid and controller code:

<div style="width:830px;font-size:x-small; padding-top:40px;">
 
        @(Html.Kendo().Grid<SystemsFormsMVC.Models.vMyForm>()
 
        .Name("Grid1")
 
        .Columns(columns=>
 
        {
 
            columns.Bound(o => o.Id);
 
            columns.Bound(o => o.SystemName);
 
            columns.Bound(o => o.FormType);
 
 
            })
              
 
            .DataSource(dataSource => dataSource
 
             .Ajax()
 
             .PageSize(5)
 
             .Read(read => read.Action("GetMyForms", "Home"))             
 
                )
 
                .Pageable()
 
                .Navigatable()
 
                .Sortable()
 
                .Filterable()
 
            )
</div>

Controller:
public ActionResult GetMyForms([DataSourceRequest] DataSourceRequest request)
{
    var query = _repository.GetMyForms(GetCurrentUserName());
    query = query.OrderBy(s => s.RequestDate);
    return Json(query, JsonRequestBehavior.AllowGet);
}
 
  
 
public IQueryable<vMyForm> GetMyForms(string UserName)
{
    SystemsFormsDataContext db = new SystemsFormsDataContext();
    IQueryable<vMyForm> query;
    Int32 UserId = GetCurrentUserId(UserName);
 
    try
    {
        query = (from s in db.vMyForms
                 where s.UserId == UserId
                 select s);   
    }
    catch (Exception ex)
    {
        query = (from s in db.vMyForms
                 where s.UserId == 0
                 select s);
    }
 
    return query;
}

Could you please help me figure out what the issue is with the data not displaying in the grid?

Thanks,  Shuja

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 18 Dec 2014, 07:54 AM
Hello Shuja,

My colleague answered to the support thread opened on the same subject. I would like to continue our discussion there if the problem is still not resolved in order to avoid duplication.

Here is a quote of the answer:

From the provided information it appears that the Controller returns the data to the Grid in invalid format - please note that the Grid expects the records to be nested in "Data" field of the response. The easiest way to achieve this is to use the "ToDataSourceResult" extension method on the data before sending it to the client side as demonstrated in the following help article:

Regards,
Georgi Krustev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Shuja
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or