1

I am trying to get a telerik grid to display json data that is being return from a controller action but the only it displays the actual json data in the browser window.

  1. Am i supposed to call .BindTo after read?
  2. Am i doing something wrong in my action?
  3. am i going about this all wrong?

        [HttpGet]
    public ActionResult ReadLeads([DataSourceRequest]DataSourceRequest request)
    {
    
    
        var model = new RecordLookupViewModel();
    
        using (var db = new RGI_MasterEntities())
        {
    
            db.Configuration.ProxyCreationEnabled = false;
    
            var results = db.tblMasterLeads
                .Where(
                    x => (model.FirstName == null || x.FirstName.Equals("Eric"))
                         && (model.RecordType == null || x.MasterLeadType.Equals("Responder"))
                )
                .Select(s => new LookupGridResults
                {
                    FirstName = s.FirstName,
                    LastName = s.LastName,
                    City = s.city,
                    State = s.state,
                    County = s.county,
                    Zip = s.zip
                }).Take(10);
    
            var result = results.ToDataSourceResult(request);
    
            return Json(result, JsonRequestBehavior.AllowGet);
    
        }
    } 
    

Hers is my view code for the grid.

                                @(Html.Kendo().Grid<LookupGridResults>()
.Name("grid")
.AutoBind(false)
.Columns(columns =>
{
    columns.Bound(p => p.FirstName).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains"))).Width(225);
    columns.Bound(p => p.LastName).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
    columns.Bound(p => p.City).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
    columns.Bound(p => p.County).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
    columns.Bound(p => p.State).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
    columns.Bound(p => p.Zip).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .ServerOperation(true)
    .Read(read => read.Action("ReadLeads", "LeadsManagement").Type(HttpVerbs.Get))

 )

                                )

Here are my results btw.

{"Data":[{"LastName":"COFFEY","FirstName":"EDWARD","City":"FRANKFORT","County":"FRANKLIN","State":"KY","Zip":"40601-2304"},{"LastName":"DESPAIN","FirstName":"TONY","City":"CAMPBELLSVILLE","County":"TAYLOR","State":"KY","Zip":"42718-9397"},{"LastName":"HALBIG","FirstName":"RONALD","City":"CAMPBELLSVILLE","County":"TAYLOR","State":"KY","Zip":"42718-1556"},{"LastName":"KRAUS","FirstName":"REBECCA","City":"FRANKFORT","County":"FRANKLIN","State":"KY","Zip":"40601-2714"},{"LastName":"LAWLESS","FirstName":"MEREDITH","City":"CAMPBELLSVILLE","County":"TAYLOR","State":"KY","Zip":"42718-1556"},{"LastName":"RANKIN","FirstName":"PAULINE","City":"LAWRENCEBURG","County":"ANDERSON","State":"KY","Zip":"40342-1374"},{"LastName":"SHIRLEY","FirstName":"LORRAINE","City":"CAMPBELLSVLLE","County":"TAYLOR","State":"KY","Zip":"42718-1557"},{"LastName":"STAPLES","FirstName":"DAMON","City":"HODGENVILLE","County":"LARUE","State":"KY","Zip":"42748-1208"},{"LastName":"WILLIAMS","FirstName":"LUCY","City":"FRANKFORT","County":"FRANKLIN","State":"KY","Zip":"40601-2308"},{"LastName":"WILSON","FirstName":"BELIDA","City":"FRANKFORT","County":"FRANKLIN","State":"KY","Zip":"40601-1321"}],"Total":10,"AggregateResults":null,"Errors":null}
6
  • the 2 parts of code you're showing looks fine.. not sure you need .AutoBind(false) sounds like you might be missing a javascript library reference Commented Feb 25, 2016 at 20:42
  • That didnt do it. I feel like im missing something. Not sure what yet. Commented Feb 25, 2016 at 20:49
  • 1
    Do you have this issue: stackoverflow.com/questions/16143886/… Commented Feb 25, 2016 at 21:31
  • 1
    This one also looks familiar: stackoverflow.com/questions/14530969/… Commented Feb 25, 2016 at 21:40
  • 1
    This one speaks to the point that @JamieD77 referenced: stackoverflow.com/questions/20829235/… Commented Feb 25, 2016 at 21:42

1 Answer 1

1

Thanks for all the help, it seemed i was missing a reference to a bundle. I do credit Mark Schultheiss for pointing me in the right direction.

Got it completly working today. Here is what fixed it.

  1. I changed my actionresult to a JsonResult.
  2. I had filtering turned on in the grid but none of my columns had filtering attributes.

I think thats about it. It works great now.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.