That worked great for my master grid but not for my detail one.
I have a master detail grid set up but when I try to export with my detail grid, I get the following error:
Unable to cast object of type 'System.Web.Mvc.JsonResult' to type 'System.Collections.IEnumerable'.
My detail grids data is loaded with the following javascript:
var state = value.data.State;
var maildate = value.data.maildate;
var datasource = data;
var detaildata = ej.DataManager(data).executeLocal(ej.Query().where("State", ej.FilterOperators.equal, state, false));
var gridObj = $("#DetailGrid").ejGrid("instance");
gridObj.dataSource(ej.DataManager(detaildata));
My export code in the controller looks like this:
public void ExportDetailGrid(string GridModel)
{
ExcelExport exp = new ExcelExport();
var DataSource = LeadsByStateCountyMailDate() ;
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, DataSource, "LeadsByStateCountyMailDate.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron");
}
My LeadsByStateCountyMailDate() is this:
public JsonResult LeadsByStateCountyMailDate()
{
var dkContext = new DKDatabaseEntities();
var result = (from m in dkContext.Mailings
join p in dkContext.Persons on m.ID equals p.MailingID
join a in dkContext.Addresses on p.ID equals a.PersonID
where m.NoMail != "T"
group a by new { a.State, m.MailDate, a.County } into gg
orderby gg.Key
select new DKDatabaseModelClass.GrossLeadsByStateCountyModel { MailDate = gg.Key.MailDate.ToString(), State = gg.Key.State, County = gg.Key.County, LeadCount =
gg.Count() }).ToList();
//ViewBag.datasource = result.ToList();
return Json(result, JsonRequestBehavior.AllowGet);
}
If I change my method from type JsonResult to a List like the method that populates my master grid, my detail grid does not populate.
Thanks