我要访问在ReportingConcrete类文件的messageLogs.cshtml文件中查询的日志LINQ查询对象
这个日志LINQ Query是从被查询的Razor GridView中搜索的对象(在messageLogs.cshtml中),我希望它被解析为ReportingConcrete类,以便它基于查询的对象输出Excel报告。
总结一下,我只想为Razor GridView中搜索的字段导出Excel报告。(如果有任何搜索的话)。
如果在Gridview中没有搜索,Excel报告应该从整个数据库的详细信息中生成。(我已经有了这个)。
ReportingConcrete.cs
messageLogs.cshtml.cs
try
{
//var logsList = await context.MessageArchive.FindAsync();
var logs = await context.MessageArchive
.Include(x => x.Conversation).ToListAsync();
if (!string.IsNullOrEmpty(Request.Form["number"])) //If only number entered
{
NumberSearched = Convert.ToString(Request.Form["number"]);
logs = logs.Where(x => x.PhoneNumber == NumberSearched).ToList(); //Gathers all results from thelogs
//logsList = logs.Where(x => x.PhoneNumber == NumberSearched).to;
}
else if (!string.IsNullOrEmpty(Request.Form["fromDate"])) //If fromDate entered
{
fromDate = Convert.ToDateTime(Request.Form["fromDate"]);
logs = logs.Where(x => x.MessageDate >= fromDate).ToList(); //Gathers all results from the fromDate
if (!string.IsNullOrEmpty(Request.Form["toDate"])) //if form has toDate. Then logs list will include toDate parameters
{
toDate = Convert.ToDateTime(Request.Form["toDate"]);
logs = logs.Where(x => x.MessageDate <= toDate).ToList();
}
}
else if (!string.IsNullOrEmpty(Request.Form["toDate"])) //If toDate entered
{
toDate = Convert.ToDateTime(Request.Form["toDate"]);
logs = logs.Where(x => x.MessageDate <= toDate).ToList(); //Gathers all results from the toDate
}
1条答案
按热度按时间b09cbbtk1#
将cshtml.cs中的对象列表解析为类,然后在ReportingConcrete类中检索和访问此类。
'归档Excel类=新建归档Excel类();