如何通过多个网页保存数据

时间:2017-01-10 02:11:41

标签: c# asp.net-mvc razor

从WebPage1开始,用户将一些数据输入文本框并根据该搜索数据执行搜索。然后用户通过链接从WebPage1导航到WebPage2。

当用户返回WebPage1时,如何保留原始搜索数据?

用户不希望在查询字符串中看到数据。但是,数据不敏感,客户端的任何数据都将在处理之前处理。

我们正在使用带Razor的C#Mvc框架。

我一直试图每次发布整个模型而不是使用Get请求。但是,这不能很好地运行,并且不会像Post-Redirect-Post那样遵循简单的Post-Redirect-Get模式。

1 个答案:

答案 0 :(得分:1)

You can use sessions to pass data from one webpage to another until you close the browser here is an example

//assuming the method below will return list of Products

var products=Db.GetProducts();

//Store the products to a session

Session["products"]=products;

//To get what you have stored to a session

var products=Session["products"] as List<Product>;

//to clear the session value

Session["products"]=null;