/// <summary> /// Renders a full MVC view to a writer. Will render with the full MVC /// View engine including running _ViewStart and merging into _Layout /// </summary> /// <param name="viewPath"> /// The path to the view to render. Either in same controller, shared by /// name or as fully qualified ~/ path including extension /// </param> /// <param name="model">The model to pass to the viewRenderer</param> /// <param name="controllerContext">Active Controller context</param> /// <param name="writer">Writer to render the view to</param> /// <param name="errorMessage">optional out parameter that captures an error message instead of throwing</param> /// <returns>String of the rendered view or null on error</returns> public static void RenderView(string viewPath, object model, TextWriter writer, ControllerContext controllerContext, out string errorMessage) { errorMessage = null; try { ViewRenderer renderer = new ViewRenderer(controllerContext); renderer.RenderView(viewPath, model, writer); } catch (Exception ex) { errorMessage = ex.GetBaseException().Message; } }
public MvcHtmlString Render() { try { var controller = ViewRenderer.CreateController <EmptyController>(); var html = ViewRenderer.RenderPartialView(FormattedViewLocation, BizForm, controller.ControllerContext); return(MvcHtmlString.Create(html)); } catch (Exception e) { EventLogProvider.LogException(nameof(FormViewRenderer), nameof(Render), e); return(MvcHtmlString.Empty); } }
/// <summary> /// Renders a full MVC view to a writer. Will render with the full MVC /// View engine including running _ViewStart and merging into _Layout /// </summary> /// <param name="viewPath"> /// The path to the view to render. Either in same controller, shared by /// name or as fully qualified ~/ path including extension /// </param> /// <param name="model">The model to pass to the viewRenderer</param> /// <param name="controllerContext">Active Controller context</param> /// <param name="errorMessage">optional out parameter that captures an error message instead of throwing</param> /// <returns>String of the rendered view or null on error</returns> public static string RenderView(string viewPath, object model, ControllerContext controllerContext, out string errorMessage) { errorMessage = null; try { ViewRenderer renderer = new ViewRenderer(controllerContext); return(renderer.RenderViewToString(viewPath, model)); } catch (Exception ex) { errorMessage = ex.GetBaseException().Message; } return(null); }