Skip to content

Instantly share code, notes, and snippets.

@geoffreysmith
Created October 5, 2011 14:12
Show Gist options
  • Save geoffreysmith/1264520 to your computer and use it in GitHub Desktop.
Save geoffreysmith/1264520 to your computer and use it in GitHub Desktop.
TempDataExtensions
public static class TempDataExtension
{
public static void Put(this TempDataDictionary tempData, string key, object value)
{
var js = new JavaScriptSerializer();
tempData[key] = js.Serialize(value);
}
public static T Get<T>(this TempDataDictionary tempData, string key) where T : class
{
var js = new JavaScriptSerializer();
object slug;
tempData.TryGetValue(key, out slug);
return slug == null ? null : js.Deserialize<T>((string)slug);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment