public static JObject FilterOutSession(ModelContext context) { context.JSONObject.Remove("Session"); return context.JSONObject; }
public static HtmlDocumentFacade PostProcessModel(this HtmlDocumentFacade doc) { if (doc.ProcessContext.ModelScriptPostProcessingInfos == null) return doc; bool addedInitializer = false; foreach (var modelProcessingInfo in doc.ProcessContext.ModelScriptPostProcessingInfos) { var node = modelProcessingInfo.Node; if (!modelProcessingInfo.NeededForClient && node.parentNode != null) //may have already been removed from doc in process server side scripts { node.parentNode.removeChild(node); continue; } else if (modelProcessingInfo.IsDumbedDown) { continue; } var hasAsync = node.hasAttribute("async"); string id = node.id; if (hasAsync) { var server = HttpContext.Current.Server; if (modelProcessingInfo.Model == null) { string src = "model.tsp.js?" + tspModelHandler.getMethod + "=" + server.UrlEncode(modelProcessingInfo.StaticMethodString) + "&" + tspModelHandler.id + "=" + server.UrlEncode(id); node.innerHTML = string.Empty; node.setAttribute("src", src); //node.appendAttribute("onload", "tsp.cs.handleAsyncModelLoad();", ";"); } else { throw new NotImplementedException(); } } else { #region embed JSON data in tag if (modelProcessingInfo.Model == null) { var result = InvokeServerSideMethod(modelProcessingInfo.StaticMethodString, null); modelProcessingInfo.Model = result; } //string string json = null; var jsonObj = JObject.FromObject(modelProcessingInfo.Model); var csFilter = modelProcessingInfo.CSFilter; if (!string.IsNullOrEmpty(csFilter)) { var mc = new ModelContext { JSONObject = jsonObj, }; var newResult = InvokeServerSideMethod(csFilter, new object[] { mc }); json = newResult.ToString(); } else { json = jsonObj.ToString(); } string initializer = addedInitializer ? null : @" if(typeof(model)=='undefined') model = {};"; string modelScript = @" model['" + id + "'] = " + json + @"; "; node.innerHTML = initializer + modelScript; addedInitializer = true; #endregion } } return doc; // //if (hasAsync) //{ //} //return doc; }