C# 无法将剑道网格数据导出到Excel电子表格
我正在从剑道网格导出数据。控制器中的代码在foreach循环中出错而中断 错误消息C# 无法将剑道网格数据导出到Excel电子表格,c#,model-view-controller,kendo-grid,llblgenpro,C#,Model View Controller,Kendo Grid,Llblgenpro,我正在从剑道网格导出数据。控制器中的代码在foreach循环中出错而中断 错误消息 -InvalidCastException- {"Unable to cast object of type '<>f__AnonymousType2`6[System.DateTime,System.String,System.Int32,System.String,System.String,System.String]' to type 'ZoomAudits.DAL.TypedView
-InvalidCastException-
{"Unable to cast object of type '<>f__AnonymousType2`6[System.DateTime,System.String,System.Int32,System.String,System.String,System.String]' to type 'ZoomAudits.DAL.TypedViewClasses.ReportPhoneSupportResultRow'."}
找到解决办法了。在文件导出操作中使用此代码
ReportPhoneSupportResultTypedView results = new ReportPhoneSupportResultTypedView();
string[] userIds = model.UserId.Split(',');
foreach (string userId in userIds)
{
int iUserId = 0;
if (Int32.TryParse(userId, out iUserId))
{
RetrievalProcedures.FetchReportPhoneSupportResultTypedView(results, model.FromDate, model.ToDate, iUserId);
}
}
//Get the data representing the current grid state - page, sort and filter
IEnumerable ExcelResults = ((IEnumerable)results).ToDataSourceResult(request).Data;
请将错误添加到您的问题中,我将其放在顶部。感谢的想法?我需要发布更多信息吗?看起来类型转换是结果集中的问题。您是否调试了代码并检查了excelresults对象的内容?所有数据都在那里?
ReportPhoneSupportResultTypedView results = new ReportPhoneSupportResultTypedView();
string[] userIds = model.UserId.Split(',');
foreach (string userId in userIds)
{
int iUserId = 0;
if (Int32.TryParse(userId, out iUserId))
{
RetrievalProcedures.FetchReportPhoneSupportResultTypedView(results, model.FromDate, model.ToDate, iUserId);
}
}
//Get the data representing the current grid state - page, sort and filter
IEnumerable ExcelResults = ((IEnumerable)results).ToDataSourceResult(request).Data;