OutputCache will cache the results for each user. Why not try to save the information in a cookie with information about the URL and filter. Each time the action is performed, read the cookie and fill out the model (user model for search) with the values ββfound (if they correspond to the URL of the page, the action is in this situation). Pass the model into the view and let it update the text fields of the search criteria and check boxes.
UPDATE: When the user fills in the text fields of the search filter, you somehow pass this information back to the controller. This is probably some kind of strongly typed object.
Say your users can enter the following information: - Criteria - Start date - EndDate
There is a model called SearchCriteria, defined as:
public class SearchCriteria { public string Criteria { get; set; } public DateTime? StartDate { get; set; } public DateTime? EndDate { get; set; } }
Your action might look something like this:
[HttpGet] public ViewResult Search() { SearchCriteria criteria = new SearchCriteria(); if (Request.Cookies["SearchCriteria"] != null) { HttpCookie cookie = Request.Cookies["SearchCriteria"]; criteria.Criteria = cookie.Values["Criteria"]; criteria.StartDate = cookie.Values["StartDate"] ?? null; criteria.EndDate = cookie.Values["EndDate"] ?? null; } return View(criteria); } [HttpPost] public ActionResult Search(SearchCriteria criteria) { // At this point save the data into cookie HttpCookie cookie; if (Request.Cookies["SearchCriteria"] != null) { cookie = Request.Cookies["SearchCriteria"]; cookie.Values.Clear(); } else { cookie = new HttpCookie("SearchCriteria"); } cookie.Values.Add("Criteria", criteria.Criteria); if (criteria.StartDate.HasValue) { cookie.Values.Add("StartDate", criteria.StartDate.Value.ToString("yyyy-mm-dd")); } if (criteria.EndDate.HasValue) { cookie.Values.Add("EndDate", criteria.EndDate.Value.ToString("yyyy-mm-dd")); } // Do something with the criteria that user posted return View(); }
This is some kind of solution. Please understand that I have not tested this, and I wrote it on top. It is designed to give you an idea of ββhow you can solve this problem. You should probably also add Action to SearchCriteria so that you can check if this is the appropriate action when you read the cookie. In addition, reading and writing a cookie should be moved to a separate method so that you can read it from other actions.
Hope this helps,
Huske
source share