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