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

Export Throwing null reference error

I am using a the Grid component and have followed the example located here http://mvc.syncfusion.com/demos/web/grid/exportinggrid

this is my razor code for the grid:

@(Html.EJ().Grid<HOMenuItemModel>("HOMenuItemGrid")
                .Datasource(ViewBag.HOMenuItems as IEnumerable<HOMenuItemModel>)
                .ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>
                {
                    items.AddTool(ToolBarItems.ExcelExport);
                    items.AddTool(ToolBarItems.WordExport);
                    items.AddTool(ToolBarItems.PdfExport);
                }))
                .IsResponsive(true)
                .EnableResponsiveRow(true)
                .AllowPaging()
                //.ClientSideEvents(e => e.RowSelected("onSelect"))
                .AllowSorting()
                .SortSettings(sort => sort.SortedColumns(col => col.Field("Description").Direction(SortOrder.Ascending).Add()))
                .Columns(col =>
                {
                    col.Field("HOItemNumber").HeaderText("HO ID").Width(40).Add();
                    col.Field("Category").HeaderText("Category").TextAlign(TextAlign.Right).Width(75).Add();
                    col.Field("Department").HeaderText("Department").TextAlign(TextAlign.Right).Width(75).Add();
                    col.Field("Description").HeaderText("Description").TextAlign(TextAlign.Right).Width(75).Add();
                    col.Field("Price1").HeaderText("Price1").Format("{0:C2}").Width(40).Add();
                    col.Field("Cost").HeaderText("Cost").Format("{0:C2}").Width(40).Add();
                    col.Field("Gross Profit").HeaderText("Gross Profit (%)").Format("{0:C2}").Width(40).Add();
                }))

and here is the code from the controller for excel exporting:

public void ExportToExcel(string GridModel)
        {
            var dbSetup = new BlueStreakSetupEntities();
            ExcelExport exp = new ExcelExport();
            var DataSource = dbSetup.MenuItems.Where();
            GridProperties obj = ConvertGridObject(GridModel);
            exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron");
        }

WHen I try the export to Excel option I get an Object reference not set to an instance of an object error. It points to the exp.Export() line of the controller code.

Any help would be greatly appreciated.

Thanks,

Nate

1 Reply

MS Mani Sankar Durai Syncfusion Team June 27, 2017 12:39 PM UTC

Hi Nate, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and we are able to reproduce the reported issue. To solve the exception that you have faced while exporting the grid please follow the below Knowledge base link. 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 


Loader.
Up arrow icon