Have a c# MVC application with SQL database, entity framework/LINQ to help with displaying classical index page.
I added Search textboxes and GO button, so that on the HTTP Post the search data is used in a LINQ statement to sort results. Works perfect. Problem? Is that once you navigate away and come back to the /Home/Index page, the searched data is gone, its back
to default (all results). So I asked about storing search results in cookies?
Added the suggested code in the controller + view. The View has textboxes cast with the contents being the [Session].search1 or 2 etc. There is a Search and Clear button, both named Submit, one value = "search" the other "clear" so that in the Controller,
that value comes across as either search/clear. Code says If(submit == "search") then connects the [Session].Search1 = search1; If clear, then it sets them as search1 = ""; using null threw a null reference exception.
So now, it will search because it just puts the search value into a [Session] object, then references that objects ToString() value. As if saying Var x = y, Var y = z, Var z = z1, just pushes out the content of the search text to another variable which
is then used, nothing more.
When you navigate into Edit and back? the /Home/Index textbox has the search data, but it did not search/filter on that data. You get the initial unfiltered full results. And for some reason, this controller View works for both Get/Post. There is only
one Index method, and dont know if its related to not showing/keeping it filtered or need to make a separate method for post/get
Expected result: /home/index/ (page displays with items) user puts in search data to a textbox, clicks SEARCH. index/ returns with filtered results. Now click on an item's edit page. You go to that Edit and do whatever, then click on the return to
Index link. it must show the filtered results.
Expected result: /home/index/ (page displays with items) user puts in search data to a textbox, clicks SEARCH. index/ returns with filtered results. Now click on an item's edit page. You go to that Edit and do whatever, then click on the return to Index
link. it must show the filtered results.
Share the source code if you want community code review or debugging support.
Member
126 Points
873 Posts
How to store user Search Results in [Session].searchinfo upon return to page?
Nov 30, 2019 05:21 PM|rogersbr|LINK
Have a c# MVC application with SQL database, entity framework/LINQ to help with displaying classical index page.
I added Search textboxes and GO button, so that on the HTTP Post the search data is used in a LINQ statement to sort results. Works perfect. Problem? Is that once you navigate away and come back to the /Home/Index page, the searched data is gone, its back to default (all results). So I asked about storing search results in cookies?
Added the suggested code in the controller + view. The View has textboxes cast with the contents being the [Session].search1 or 2 etc. There is a Search and Clear button, both named Submit, one value = "search" the other "clear" so that in the Controller, that value comes across as either search/clear. Code says If(submit == "search") then connects the [Session].Search1 = search1; If clear, then it sets them as search1 = ""; using null threw a null reference exception.
So now, it will search because it just puts the search value into a [Session] object, then references that objects ToString() value. As if saying Var x = y, Var y = z, Var z = z1, just pushes out the content of the search text to another variable which is then used, nothing more.
When you navigate into Edit and back? the /Home/Index textbox has the search data, but it did not search/filter on that data. You get the initial unfiltered full results. And for some reason, this controller View works for both Get/Post. There is only one Index method, and dont know if its related to not showing/keeping it filtered or need to make a separate method for post/get
Expected result: /home/index/ (page displays with items) user puts in search data to a textbox, clicks SEARCH. index/ returns with filtered results. Now click on an item's edit page. You go to that Edit and do whatever, then click on the return to Index link. it must show the filtered results.
All-Star
53051 Points
23634 Posts
Re: How to store user Search Results in [Session].searchinfo upon return to page?
Dec 01, 2019 02:20 PM|mgebhard|LINK
Share the source code if you want community code review or debugging support.