开发者

Go back to a search page without losing search criteria

开发者 https://www.devze.com 2023-02-22 07:20 出处:网络
I need some help on this problem. It is about ASP.NET MVC3. I have a page with at the top some search criteria and at the bottom the resulting data. The user can type some criteria and use a submit bu

I need some help on this problem. It is about ASP.NET MVC3. I have a page with at the top some search criteria and at the bottom the resulting data. The user can type some criteria and use a submit button to retieve data. In my controller, I have an ActionResult function for managing these criteria and return to the same page with a ViewModel class filled.

The problem: the user can click on a line in the resulting table for view开发者_运维问答ing a detail page. On the detail page, he can navigate to an edit page for editing data. On this page (edit data) I would like to able the user to go back to the search result page (in fact: navigate back two times). What is the best way to proceed? If I "simply" use an ActionLink (without posting data) to my search result page, it will simply display an empty result page with empty search criteria. Maybe I need to keep my search criteria in a session variable? I don't like this kind of thing...

Any help will be highly appreciated.


Why not place the data in the Session, as you say?

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

This way you have the search criteria available no matter how many "back clicks" the user does.

You could make it much more complicated but I do not think it is necessary in this case. If you want to pass it as route data in an action link you'll have to defensively add a searchCriteria parameter to every ActionLink of the pages the user might navigate to from the Search page. That makes it a lot more cumbersome in my opinion.

Good enough is sometimes good enough. Refactor later as needed. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消