2016-02-25 104 views
0

我想获得一个telerik网格来显示从控制器操作返回的json数据,但只有它显示浏览器窗口中的实际json数据。MVC Telerik网格不绑定只在浏览器中显示json数据

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

) 

           ) 

这是我的结果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} 
+0

你显示的代码的两部分看起来很好......不知道你需要'.AutoBind(false)'听起来像你可能会缺少一个JavaScript库参考 – JamieD77

+0

这没有做到这一点。我觉得我想失去一些东西。还不确定。 – jeffkenn

+1

你有这个问题:http://stackoverflow.com/questions/16143886/kendo-ui-grid-shows-json-instead-of-grid-asp-net-razor –

回答

0

感谢您的所有帮助,似乎我错过了对包的引用。我信任Mark Schultheiss指引我朝着正确的方向前进。

今天完成工作。这是什么修复它。

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

我认为这是关于它。它现在很好用。