开发者

Cant store Hash table in session - Asp.net MVC3

开发者 https://www.devze.com 2023-04-09 19:00 出处:网络
In my application I want to store a hash tablein session and retrieve later from session. The code is shown below

In my application I want to store a hash table in session and retrieve later from session.

The code is shown below

     Hashtable ht = new Hashtable();
                   DateTime fromDate = Convert.ToDateTime(dt.Rows[0]["FromDate"]);
                   DateTime toDate = Convert.ToDateTime(dt.Rows[0]["ToDate"]);
                   ht["StartTime"] = fromDate;
                   ht["EndTime"] = toDate;
                   Session["RuleSearchParameterForArchive"] = ht;

While debuggin i can see that hashtable ht hold two values (StartTime and EndTIme) .. But when i retri开发者_JS百科eving ,that always give null .. code is shown below

  Hashtable hts = (Hashtable)Session["RuleParametersForArchive"];
                   DateTime dd = Convert.ToDateTime(hts["EndTime"]);

While debugging i can see that hastable hts holds null value. Why i cant retrieve value from session. Any ideas??


The hashtable is stored with a different key (RuleSearchParameterForArchive) than you use when attempting to retrieve it (RuleParametersForArchive).

0

精彩评论

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

关注公众号