Return to the search page without losing your search criteria.

I need help on this issue. It's about ASP.NET MVC3. I have a page with the tops of some search criteria, and the bottom is the data. The user can enter some criteria and use the send button to transfer data. In my controller, I have an ActionResult function to manage these criteria and return to the same page with the ViewModel class populated.

Problem : the user can click on a row in the resulting table to view the detailed page. On the details page, he can go to the edit page to edit the data. On this page (edit data), I would like the user to be able to return to the search results page (actually: go back two times). What is the best way? If I β€œjust” use ActionLink (without posting data) on my search results page, it will simply display a blank results page with empty search criteria. Maybe I need to save search criteria in a session variable? I do not like it...

Any help would be greatly appreciated.

+4
source share
1 answer

Why not put data in a Session , as you say?

 public ActionResult Search(string searchCriteria) { Session["searchCriteria"] = searchCriteria; // do more stuff } 

Thus, you have search criteria, no matter how many β€œback-clicks” a user makes.

You can make it a lot harder, but I don't think it is necessary in this case. If you want to pass it as route data in an action link, you will have to protect the searchCriteria parameter for each ActionLink page that the user can go to from the search page. This makes it much more cumbersome in my opinion.

Good enough, sometimes enough. Refactor later as needed. :)

+2
source

Source: https://habr.com/ru/post/1346707/


All Articles