Problem
When we export the grid with foreign key columns, the dataSource type of the foreign key columns is passed as generic object to the export function. As we don’t have support to export generic type list, a null exception is thrown like mentioned below.
<Exception>
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Syncfusion.EJ.Export
StackTrace:
at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordCell(Object row, Column column)
at Syncfusion.EJ.Export.GridExcelExport.<>c__DisplayClasse.<ProcessRecordRow>b__d(Column column)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordRow(Object row)
at Syncfusion.EJ.Export.GridExcelExport.RenderRecord()
at Syncfusion.EJ.Export.GridExcelExport.ProcessGridContents()
at Syncfusion.EJ.Export.GridExcelExport.IterateElements()
at Syncfusion.EJ.Export.GridExcelExport.ExportHandler()
at Syncfusion.EJ.Export.GridExcelExport.ExecuteResult(GridProperties GridModel, IEnumerable dataSource)
at Syncfusion.EJ.Export.GridExcelExport.Export(GridProperties gridModel, IEnumerable dataSource, Boolean multipleExport)
at Syncfusion.EJ.Export.ExcelExport.Export(GridProperties gridmaodel, IEnumerable datasource, String excelname, ExcelVersion excelversion, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme)
at EMIMReports._Default.dgReport_OnServerExcelExporting(Object sender, GridEventArgs e) in C:\Visual Studio Projects\2014\ESJS\EMIMReports\EMIMReports\Default.aspx.vb:line 99
at Syncfusion.JavaScript.Web.Grid.PostBackEventHandler(String EventName, Dictionary`2 args)
at Syncfusion.JavaScript.Web.CommonDataBoundControl.RaisePostBackEvent(String EventArgument)
InnerException:
</Exception>
Reason
Since we have deserialized the grid model obtained from the client side (where the column dataSource is a generic JSON object), it is deserialized to generic list
Solution
In order to overcome this issue, we need to dynamically set the dataSource for the foreign key columns before calling the Export method as explained in the below example.
Grid Rendering Code.
Code Behind
This information should really be added to the main documentation around exporting -> https://help.syncfusion.com/aspnetmvc/grid/exporting
Fixed my problem.
Thanks,
H