I have a web application where I have some search fields. I need to export the search result to excel sheet. I have tried storing the results in session but that slowed down the whole application. What is the efficient way to do it?
Below is the sample of the codes I tried. Any suggestions, comments, solutions will be highly appreciated. Thank you
- public class APPET1Controller : Controller
- {
- private APContext db = new APContext();
-
- public ActionResult Index(string search, string cagecode, string sortBy, int? page, string docNumber, string remark, string status)
- {
- APPETViewModel viewModel = new APPETViewModel();
- 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 = new SelectList(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>(); return View(viewModel); }