We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to handle null exception when exporting grid with foreign key columns?

Platform: ASP.NET MVC |
Control: Grid

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

 

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Henryk Schneider
Apr 27, 2018

This information should really be added to the main documentation around exporting -> https://help.syncfusion.com/aspnetmvc/grid/exporting

Fixed my problem.

Thanks,

H

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile