MVC Telerik 网格未绑定仅在浏览器中显示 json 数据

MVC Telerik grid not binding only displaying json data in browser

我正在尝试让 telerik 网格显示 json 来自控制器操作的 return 数据,但只有它在浏览器中显示实际 json 数据 window。

  1. 我应该在读取后调用 .BindTo 吗?
  2. 我是不是做错了什么?
  3. 我是不是做错了?

        [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);
    
        }
    } 
    

她的是我的网格视图代码。

                                @(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))

 )

                                )

顺便说一句,这是我的结果。

{"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}

感谢您的所有帮助,我似乎缺少对捆绑包的引用。我确实感谢 Mark Schultheiss 为我指明了正确的方向。

今天完成了。这是修复它的方法。

  1. 我将 actionresult 更改为 JsonResult。
  2. 我在网格中打开了过滤功能,但 none 个列具有过滤属性。

我想就是这样。现在效果很好。