将数据从一个页面传递到另一个页面.net
问题描述:
我在面试中被问到以下情况。将数据从一个页面传递到另一个页面.net
我需要在.net web窗体或MVC中将数据从一个页面传递到另一个页面。但我不能使用以下内容。 1.会话 2.隐藏字段 3.饼干 4.视图状态 5.应用程序状态 6.查询字符串
任何另一种方式????
答
您可以试试这个以供参考,此时有多种方法但是这个 记得。
//For saving in cache
WebCache.Set("test", "any data comes here", 10, false); // Cache the value for 10 minutes
//Retrieving the data
string test = WebCache.Get("test");
if(!string.IsNullOrEmpty(test))
{
//get test value here
}
else
{
//No data msg
}
答
您还可以使用Public Properties
摆脱的源页面数据到目标页面:
源页面
public String MyValue
{
get
{
return TexBoxMyValue.Text;
}
}
在目标页面,添加@PreviousPageType
页指向源页面的指令,并使用PreviousPage.
<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>
Label1.Text = PreviousPage.MyValue;
愚蠢的面试问题,何必呢......?有一些方法可以做到,但我不确定它是否适合这个网站来回答它。 – walther 2014-09-01 11:04:05
您可以使用HTTP请求正文或HTTP请求标题。 – Romoku 2014-09-01 11:04:43
@Romoku你能提供一个简单的例子吗? – 2014-09-01 11:15:40