/// <summary> /// Renders the using controller. /// </summary> /// <param name="engine">The engine.</param> /// <param name="gridContext">The grid context.</param> /// <param name="helper">The helper.</param> /// <returns>System.String.</returns> /// TODO Edit XML Comment Template for RenderUsingController private static string RenderUsingController( GridEngine engine, GridContext gridContext, HtmlHelper helper) { var model = engine.GenerateModel(gridContext); var controllerContext = helper.ViewContext.Controller .ControllerContext; var vdd = new ViewDataDictionary(model); var tdd = new TempDataDictionary(); using (var sw = new StringWriter()) { var viewResult = ViewEngines.Engines.FindPartialView( controllerContext, gridContext.GridDefinition.ViewPath); var viewContext = new ViewContext( controllerContext, viewResult.View, vdd, tdd, sw); viewResult.View.Render(viewContext, sw); viewResult.ViewEngine.ReleaseView( controllerContext, viewResult.View); return(sw.GetStringBuilder().ToString()); } }
/// <summary> /// Renders the using rendering engine. /// </summary> /// <param name="engine">The engine.</param> /// <param name="gridContext">The grid context.</param> /// <returns>System.String.</returns> /// TODO Edit XML Comment Template for RenderUsingRenderingEngine private static string RenderUsingRenderingEngine( GridEngine engine, GridContext gridContext) { var renderingEngine = GetRenderingEngine(gridContext); using (var ms = new MemoryStream()) { using (TextWriter tw = new StreamWriter(ms)) { engine.Run(renderingEngine, gridContext, tw); } var result = LocalEncoding.GetString(ms.ToArray()); return(result); } }
/// <summary> /// Renders the preloaded grid HTML. /// </summary> /// <param name="helper">The helper.</param> /// <param name="grid">The grid.</param> /// <param name="gridName">Name of the grid.</param> /// <param name="pageParameters">The page parameters.</param> /// <returns>System.String.</returns> /// <exception cref="InvalidOperationException"></exception> /// TODO Edit XML Comment Template for RenderPreloadedGridHtml private static string RenderPreloadedGridHtml( HtmlHelper helper, IMvcGridDefinition grid, string gridName, object pageParameters) { string preload; var options = QueryStringParser.ParseOptions( grid, HttpContext.Current.Request); var pageParamsDict = new Dictionary <string, string>( StringComparer.OrdinalIgnoreCase); if (pageParameters != null) { foreach (PropertyDescriptor descriptor in TypeDescriptor .GetProperties(pageParameters)) { var obj2 = descriptor.GetValue(pageParameters); if (obj2 != null) { pageParamsDict.Add(descriptor.Name, obj2.ToString()); } } } if (grid.PageParameterNames.Count > 0) { foreach (var aqon in grid.PageParameterNames) { var val = ""; if (pageParamsDict.ContainsKey(aqon)) { val = pageParamsDict[aqon]; } options.PageParameters[aqon] = val; } } var gridContext = GridContextUtility.Create( HttpContext.Current, gridName, grid, options); var engine = new GridEngine(); switch (grid.RenderingMode) { case RenderingMode.RenderingEngine: preload = RenderUsingRenderingEngine(engine, gridContext); break; case RenderingMode.Controller: preload = RenderUsingController(engine, gridContext, helper); break; default: throw new InvalidOperationException(); } return(preload); }