我正在使用 C# 作为代码隐藏。
我有很多值是在提交我的表单时发布的,下面是其中的一些值:
skywardsNumber 99999039t
password a2222222
ctl00$MainContent$ctl22$FlightSchedules1$ddlDepartureAirport-suggest Alice Springs (ASP)
ctl00$MainContent$ctl22$ctl07$txtPromoCode ManojPromo
现在我想将所有 FORM 发布的值存储在 asp.net 字典中,然后该字典对象将保存在 SESSIONS 中以供进一步使用。
请建议如何将 FORM POSTED 值存储在 asp.net DICTIONARY 中。
请您参考如下方法:
试试这个方法:
using System.Linq;
using System.Collections;
using System.Collections.Generic;
...
Dictionary<string, string> form = new Dictionary<string, string>(from key in Request.Form.AllKeys select new DictionaryEntry(key, Request.Form[key]));
Session["MyKey"] = form;
更新
没有 LINQ:
Dictionary<string, string> form = new Dictionary<string, string>();
foreach(string key in Request.Form.AllKeys)
form.Add(key, Request.Form[key]);
Session["MyKey"] = form;
