views:

194

answers:

2

I have a simple ASP.NET MVC application, like movie sample. In the list.aspx page I have a grid, the grid has information from the database. I can fill the grid by search criteria.

For example, I select product.cost < 60, I commit. The grid is filled with product, where product cost<60.

After I click to details to view details of one product from result set. After I click on Back to list (html.ActionLink("Back to list", "Index"). And in this moment generated my question. Because, will be shown all products.

What is the best way to save previous search criteria? (I need, when I click to "back to list", previously saved search criteria).

+1  A: 

You can pass search criteria parameters as query string ex: <%= Html.ActionLink("Search", "Index", "Search", new {var=value1,var2=value2 }, new { })%>

or you can also save criteria into Session object, but I think that passing it as query string is better solution for you.

dario
please, can you prefer to me , where can i read about session objects?
loviji
You find info about it here: http://www.aspfree.com/c/a/ASP.NET/Application-and-Session-Objects-in-ASP.NET/
Tony
Session state can be used in the same way like in ASP.NET webforms, see: http://wiki.asp.net/page.aspx/57/session/
dario
@dario: anonymous users preferences also can be saved in session?
loviji
Yes. You can save current user (anonymous too) settings
dario
A: 

Place your search criterion on a Stack. Then you can just pop off as you have 'used' the criteria, and so get back to the previous criteria you have.

Tony
as I understand, save each query in database. and pop it by userid.
loviji
No, I'd just use a Stack object. Don't bother saving it to a database, because each time you run your app, queries might be different, unless I've misunderstood the way you app seems to work.
Tony
@Tony: Stack object? What it is?
dario
Here's a link: http://msdn.microsoft.com/en-us/library/system.collections.stack.aspx
Tony
Tony - out of curiosity, would you then put this information in the user's session?
Andrew
@Andrew, Yes I'd save in the users session. Why do you ask?
Tony
@Tony - I ask mostly because that may not have been obvious to loviji =)
Andrew