public static void SetView(DeferredView view) { if (_views.ContainsKey(view.Name)) { _views[view.Name] = view; } else { _views.Add(view.Name, view); } }
public static DeferredView GetView(string viewName) { DeferredView result = null; if (_views.ContainsKey(viewName)) { result = _views[viewName]; } return(result); }
public ActionResult GetContent(string name, bool reload = false) { DeferredView view = GetView(name); if (view == null) { return(Json(new { Data = "error", Success = false, Message = "Deferred View {0} was not found"._Format(name), ContentReady = true })); // ContentReady to prevent further attempts to retrieve content } return(Json(new { Data = GetContentString(name, reload), Success = true, ContentReady = view.ContentReady })); }
public static string GetContentString(string name, bool reload = false) { string value = DefaultView.Content.ToHtmlString(); if (_views.ContainsKey(name)) { DeferredView view = _views[name]; if (reload) { value = view.ContentProvider(view).ToHtmlString(); } else { value = view.ContentReady ? view.Content.ToHtmlString() : view.State.ToHtmlString(); } } return(value); }
public static void CleanUp() { if (!_cleaning) { _cleaning = true; DateTime now = DateTime.Now; string[] keys = _views.Keys.ToArray(); for (int i = 0; i < keys.Length; i++) { string key = keys[i]; DeferredView view = _views[key]; TimeSpan age = now.Subtract(view.Created); if (age > MaxViewAge) { _views.Remove(key); } } _cleaning = false; } }
public DeferredViewState(DeferredView view, object model = null) { this.View = view; this.Model = model; }