I have a web application and multiple search options. I need to export the result in excel sheet. I tried storing the result in session and export it to excel, it works fine with small database, but when I tried with large database, my application slowed down a lot. What would be the best way to export my search result to excel sheet?
Below is my controller code
publicclass APPET1Controller :Controller{privateAPContext db =newAPContext();// GET: APPET1publicActionResultIndex(string search,string cagecode,string sortBy,int? page,string docNumber,string remark,string status){APPETViewModel viewModel =newAPPETViewModel();var aPPET1 = db.APPET1.Include(t =>T.APPETMedia).Include(t => t.Status).Include(t => t.APPETCCode).Include(t => t.APPETDType);............some more codes..............DateTime searchDate;if(!String.IsNullOrEmpty(search)){bool isDateSearch =DateTime.TryParse(search,out searchDate);if(isDateSearch){
aPPET1 = aPPET1.Where(s => s.Date_Received== searchDate);}else{
aPPET1 = aPPET1.Where(t.Doc_Number.Contains(search)|| t.Status.Status1.Contains(search)|| t.Remark.Contains(search)|| t.CCode.Contains(search));..............some more codes..............
viewModel.Search= search;}}var stats = db.Status.Select(s => s.Status1);
viewModel.Statuses=newSelectList(stats);{if(!String.IsNullOrEmpty(status)){
aPPET1 = aPPET1.Where(t => t.Status.Status1.Contains(status));}}if(!String.IsNullOrEmpty(docNumber)){
aPPET1 = aPPET1.Where(t => t.Doc_Number.Contains(docNumber));}if(!String.IsNullOrEmpty(remark)){
aPPET1 = aPPET1.Where(t => t.Remark.Contains(remark));}............some more codes.........Session["SearchResults"]= aPPET.ToList<APPET>();returnView(viewModel);}