I have a page displaying a table of data pulled from a database. The data is filtered to show the last 6 months of data. I want to put a check box on the page where the user can click on the checkbox to toggle between seeing all the data from all time, to the filtered last 6 months of data. Heres what I have so far:
HTML:
<input type="checkbox" name="datefilter" class="form-check-input" onChange="this.form.submit()">
Display All Time Data
Controller:
public ActionResult Index(string[] datefilter, string SearchString, string sortOrder, int? page)
{
DateTime testDate = DateTime.Now.AddMonths(-3);
var PatientID = from p in db.PatientTbls
select p;
if (datefilter == null)
{
PatientID = PatientID.Where(s => s.CreationDate >= testDate);
}
PatientID = PatientID.OrderByDescending(s => s.CreationDate);
if (!String.IsNullOrEmpty(SearchString))
{
PatientID = PatientID.Where(s => s.ReadOnModel.Contains(SearchString) || s.ToBeMarkedOnLaser.Contains(SearchString) || s.Brand.Contains(SearchString));
}
return View(PatientID.ToList().ToPagedList(page ?? 1, 150));
}
My thought was to have the checkbox re-submit the form with the new checked value and the "if" statement would then filter or not filter the results. The issue is when I check the box, it refreshes the page which then clears the checkbox. Also once I check the box once, it forever does not run the date filter query. Any help would be great.
PS. I'm new to all this so please bear with me.
Thanks
Aucun commentaire:
Enregistrer un commentaire