/// <summary> /// Saves the after having been loaded within the same remote method. /// Reloads potentially modified members in the M object to make /// changes visible in WebSharper. /// </summary> /// <typeparam name="M"></typeparam> /// <param name="stored">The stored.</param> /// <returns>The VIewState string</returns> public static string Save <M>(ViewModel <M> stored) where M : class, IStored <M>, new() { stored.SaveMembers(); // Captures members directly mutable on the client side. stored.LoadMembers(); // Mirrors side effects of methods on M in the ViewModel. switch (stored.SessionStorage) // guaranteed here, whether overridden or not { case Storage.ViewState: var filter = StorageImplementation.EncryptViewState(Configuration); stored.SerializeMain(filter); // save locally into the object return(stored.ViewState); case Storage.Session: StorageImplementation.SaveSession(Configuration, HttpContext, stored.Main); return(null); case Storage.Database: StorageImplementation.SaveDatabase(Configuration, HttpContext, stored.Main); return(null); default: throw new NotImplementedException(String.Format( "Storage {0}", stored.SessionStorage)); } }
/// <summary> /// Add the ViewState input to the ViewBag for rendering in the view /// </summary> public static void SaveViewState(this IPersistentController inst) { inst.ViewBag.SessionStorage = ViewBagSessionStorage(inst, Storage.ViewState); var filter = StorageImplementation.EncryptViewState(inst.Configuration); inst.ViewBag.ViewState = ViewState(inst, filter); }
public static void SaveHeader(this IPersistentController inst) { var filter = StorageImplementation.EncryptViewState(inst.Configuration); inst.HttpContext.Response.Headers[StorageImplementation.HeaderName] = StorageImplementation.ViewState(inst, filter); }