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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Export Throwing null reference error

Thread ID:

Created:

Updated:

Platform:

Replies:

131177 Jun 26,2017 06:30 PM UTC Jun 27,2017 12:39 PM UTC ASP.NET MVC 1
loading
Tags: Grid
Nate Greene
Asked On June 26, 2017 06:30 PM UTC

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

Mani Sankar Durai [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;