I would like to test for null to avoid exception. I receive list of objects which i have to export to excel and display in Grid.Mvc
Excel export:
sheet.Cells["A" + i].Value = item.Car.Door.Code; //FLCo
Grid display:
columns.Add(c => c.Car.Door.Code).Titled("FLCo");
The thing is Car can be null, Door can be null.
Q1: For the excel export, my solution is to use a couple of
if/else
(any better way)?For the Grid display:
if/else
or "?" operator is not supported inside the linq
the following will generate error
columns.Add(c => c.Car==null?"":(c.Car.Door==null?"":c.Car.Code)).Titled("FLCo");
error:
Cannot convert lambda expression to type 'GridMvc.Columns.IGridColumn' because it is not a delegate
Q2: Any idea how to solve this?