To keep things simple, can you just add int? Year, int? Qtr, string Div parameters int? Year, int? Qtr, string Div int? Year, int? Qtr, string Div int? Year, int? Qtr, string Div to your Index action and search using them:
public ActionResult Index(int? Year, int? Qtr, string Div) { var data= db.JobRecaps.AsQueryable(); if(Year.HasValue) data= data.Where(x=>x.Year == Year); if(Qtr.HasValue) data= data.Where(x=>x.Qtr == Qtr ); if(!string.IsNullOrEmpty(Div)) data= data.Where(x=>x.Div == Div ); return View(data.ToList()); }
Note:
You can also separate the problems and create a JobRecapSearchModel containing these search parameters, and use it as an action parameter, and create a JobRecapBusinessLogic class containing the List<JobRecap> Search(JobRecapSearchModel searchMode) with the business that I used above. Thus, you will have a more flexible and beautiful controller.
To learn more about how to use this method and benefits, you can take a look at this question:
source share