简体   繁体   中英

Error populating a kendo grid using Json

I'm trying to fill a kendo grid from my controller, but my datasource has a entity class that can be null in some cases. Everything work well, except when my entity has a null value.

  [HttpPost] public ActionResult Read([DataSourceRequest] DataSourceRequest request, Filter val) { List<Incidencia> vObj = _casosService.GetDatos(); if (null != val.Desc && val.Desc.Length > 0) vObj = vObj.Where(o => o.Description.ToLower().Contains(val.Desc.ToLower()) || o.Tittle.ToLower().Contains(val.Desc.ToLower()) .ToList(); return Json(vObj.OrderByDescending(o => o.Date).ToDataSourceResult(request, o => new { o.Id, o.EventDate, o.Description, o.System.shortName, o.Tittle, o.IdUserReport, o.Close, o.CloseDate, o.Customers.ShortName // <-- Throw an exception if has a null value. }) ); } 

I will appreciate your help.

为什么不执行以下操作?

  o.Customers != null ?   o.Customers.ShortName  : "" 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM