0

I have some search functionality in Index.cshtml where the user can perform search based on email. The search returns a grid of users.

The grid has a name column which is a href. On click it takes me to another userInfo view after making a call to Users/Info/{userid} in the UsersController.

All of this works great, but after the userInfo.cshtml is displayed, the back button is not working. I tried my best. It looks like prg pattern but I am not saving any data here.

Back button should either take me back to the page where they can click on the search and enter a email. It could also cache the email that was previously entered, perform the search and then show a grid.

enter image description here

Index.cshtml

"ajax": {
    "url": "Users/LoadUsersData",
    "type": "POST",
    "datatype": "json",
    data: {
        User: {
            Email: $('#User_Email').val(),
            )
        }
user575219
  • 2,346
  • 15
  • 54
  • 105
  • You can either `method="GET"` the form, or set cache headers to allow the user to see a stale result. https://stackoverflow.com/questions/626057/is-it-possible-to-cache-post-methods-in-http – Jeremy Lakeman Oct 12 '22 at 04:57
  • @JeremyLakeman: Thank you for the comment. Which one would you do? Is it safe to cache the response and how many minutes would it be cache. After the time expires.. will they get the error again. Regarding GET, can I use GET with Request.Form IFormCollection? – user575219 Oct 12 '22 at 14:47
  • IMHO GET if you aren't changing any data. If you are changing data, redirect from a post to a get (on success). Then there shouldn't be any posted forms in the browser history. – Jeremy Lakeman Oct 13 '22 at 00:09
  • Hi @user575219, have your considered forcing view to reload when you click the browser back button? – Rena Oct 13 '22 at 01:44
  • @Rena: I didn't try that. How do I get a hold of the browser back button click event? – user575219 Oct 13 '22 at 11:48
  • Hi @user575219, check the answer here: https://stackoverflow.com/a/67801302/11398810 – Rena Oct 14 '22 at 00:54

0 Answers0