1.两个页面(第一个页面,第二个页面)
第一个页面录入完成点击下一步,跳转到第二个页面,数据录入完毕之后点击提交,将数据添加到数据库中:
private Hashtable SaveInfo(Model model)
{
Model.test test1 = new Model.test();
test1.phone = model.UserMobile; //手机号码
test1.name = model.UserName; //姓名
test1.cjiname = model.Company; //公司名称
test1.job = model.UserPosition; //职位
test1.email = model.UserEmail; //邮箱
//实例化Hashtable,将第一页的数据存储到Hashtable中。
Hashtable ht = null;
if (Session["step1"] == null && Session["step1"] != "")
ht = new Hashtable(); //实例化一个Hashtable。
else
ht = (Hashtable)Session["step1"];
string[] filed = { "UserName", "company", "UserPosition", "UserEmail", "Phone" };
string[] filedValue = { test1.name, test1.cjiname, test1.job, test1.email, test1.phone};
for (int i = 0; i < filed.Length; i++)
{
string key = filed[i].ToString();
string value = filedValue[i].ToString();
if (ht.Contains(key))
{
ht.Remove(key);
ht.Add(key, filedValue[i].ToString());
}
else
{
ht.Add(key, value);
}
}
Session["step1"] = ht;
return ht;
}
2.将Session中存储的Hashtable数据根据key循环遍历得到value,将遍历得到的数据赋给当前页面的实体类,然后提交即可。
private void SaveAnswerPageInfo(Model model)
{
Hashtable firstInfo = new Hashtable();
firstInfo = (Hashtable)Session["step1"];
string phonevalue = "";
string UserNamevalue = "";
string companyvalue = "";
string UserPositionvalue = "";
string UserEmailvalue = "";
foreach (System.Collections.DictionaryEntry de in firstInfo)
{
if (de.Key.ToString() == "Phone")
{
phonevalue = de.Value.ToString();//得到值
break;//退出foreach遍历
}
}
foreach (System.Collections.DictionaryEntry de in firstInfo)
{
if (de.Key.ToString() == "UserName")
{
UserNamevalue = de.Value.ToString();//得到值
break;//退出foreach遍历
}
}
foreach (System.Collections.DictionaryEntry de in firstInfo)
{
if (de.Key.ToString() == "company")
{
companyvalue = de.Value.ToString();//得到值
break;//退出foreach遍历
}
}
foreach (System.Collections.DictionaryEntry de in firstInfo)
{
if (de.Key.ToString() == "UserPosition")
{
UserPositionvalue = de.Value.ToString();//得到值
break;//退出foreach遍历
}
}
foreach (System.Collections.DictionaryEntry de in firstInfo)
{
if (de.Key.ToString() == "UserEmail")
{
UserEmailvalue = de.Value.ToString();//得到值
break;//退出foreach遍历
}
}
ZHGLModel.phone = phonevalue;
ZHGLModel.name = UserNamevalue;
ZHGLModel.cjiname = companyvalue;
ZHGLModel.job = UserPositionvalue;
ZHGLModel.email = UserEmailvalue;
}