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

Grid will not display JSON data

4 Answers 401 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zoom
Top achievements
Rank 1
Zoom asked on 12 Jun 2014, 05:19 PM
I have looked at similar postings but I am unable to figure it out. The json data is displaying as text, not through the view

CONTROLLER
[HttpPost]
        public JsonResult ReportsPhoneSupport([DataSourceRequest] DataSourceRequest request, ReportsPhoneSupport model)
        {
            string[] userIds = model.UserId.Split(',');
            ReportPhoneSupportResultTypedView results = new ReportPhoneSupportResultTypedView();
            foreach (string userId in userIds)
            {
                int iUserId = 0;
                if (Int32.TryParse(userId, out iUserId))
                {
                     
                    RetrievalProcedures.FetchReportPhoneSupportResultTypedView(results, model.FromDate, model.ToDate, iUserId);
                }
            }
            var Results = from Reslt in results
                          select new{
                              ActivityDate = Reslt.ActivityDate,
                              Action = Reslt.Action,
                              Assignment = Reslt.Assignment,
                              Description = Reslt.Description,
                              Result = Reslt.Result,
                              ToFrom = Reslt.ToFrom
                          };
            return Json(Results.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
             
        }
VIEW
@{
    ViewBag.Title = "ReportsPhoneSupport";
}
 
<h2>ReportsPhoneSupport</h2>
 
 
@(Html.Kendo().Grid<ZoomAudits.DAL.TypedViewClasses.ReportPhoneSupportResultRow>()
    .Name("grid")
     
    .Columns(columns =>
    {
        columns.Bound(m => m.ActivityDate).Format("{0:MM/dd/yyyy}").Title("Activity Date");
        columns.Bound(m => m.Assignment).Title("Assignment");
        columns.Bound(m => m.Action).Title("Action");
        columns.Bound(m => m.ToFrom).Title("ToFrom");
        columns.Bound(m => m.Result).Title("Result");
        columns.Bound(m => m.Description).Title("Description");
    })
     
    //.AutoBind(true)
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
     
    .DataSource(dataBinding => dataBinding
        .Ajax()
        .ServerOperation(false)
        .PageSize(20)
             
                .Read(read => read.Action("ReportsPhoneSupport", "ReportsPhoneSupport"))
     )
)
Example of displayed data 
{"Data":[{"ActivityDate":"\/Date(1398866129000)\/","Action":"Call Placed","Assignment":9538,"Description":"Spoke with insured, Krsto Djurovski (Chris),

4 Answers, 1 is accepted

Sort by
0
Lee
Top achievements
Rank 1
answered on 13 Jun 2014, 04:12 PM
I'm having same issue so if you come across solution please reply and I'll do the same.  I'm new to MVC.  So I originally created my model and then created a controller and views using the scaffolding wizard.  Data is there all is good.  Now I want to re-write my index to use the grid.  I've studied the code in the samples. 

I see that they are sending a Serialized JSON result through the Read action.  So I create a  Service (MaterialService) that returns an IEnumerable(Material)  and call it from my Material_read Action.  I initialize my service as

private MaterialService = materialService = new MaterialService(new WMSDBContext));

in my controller (MaterialsController)

Then I'm  returning Json(MaterialService.Read().ToDataSourceResult(request) 

Then in my Razor code for my new view I have the

.read(read => read.Action("Material_Read", "Materials"))  

Everything compiles and runs but when I view in browser the grid is blank.
0
Zoom
Top achievements
Rank 1
answered on 14 Jun 2014, 05:40 PM
Anyone have any ideas? I wouldn't think it would be this hard to resolve? are the Ajax calls going to the wrong controllers? Is a GET call not being made?
0
Accepted
Daniel
Telerik team
answered on 16 Jun 2014, 02:06 PM
Hi,

@Jamie
Is the scenario the same as the one described in the support ticket that you have submitted on the same topic? If yes, then please check my reply from the ticket below:

With the current setup, the problem will occur because the form will make a POST request by default and so the JSON action method will be called instead of the one that returns the partial view. If the result should be displayed on a different view then you should make a request to an action method without a GET filter that returns a ViewResult with the grid. If the result should be displayed on the same page from a partial view then you could use Ajax.BeginFor helper to load it via Ajax. The action should be renamed in this case or the form should be configured to make a GET request instead of POST. 
Another possible solution is to render the partial view on the "reports" view and then use the grid dataSource filter method to apply the filters or pass the values with the request data and read the dataSource again.

@Lee

The code that you provided looks correct. Could you check the what is the response from the server in the network traffic? It should reveal what exactly is going wrong. I would also suggest to check the Grid troubleshooting documentation. It lists the most common reasons for the data not to be loaded.

Regards,
Daniel
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.

 
0
Lee
Top achievements
Rank 1
answered on 16 Jun 2014, 08:39 PM
I was able to get it to work.  But changed my method.  I found a sample that was using the "BindTo"  So I bound it to my model and the grid worked.   So for my purposes this is ok.  :)
Tags
Grid
Asked by
Zoom
Top achievements
Rank 1
Answers by
Lee
Top achievements
Rank 1
Zoom
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or