/// <summary> /// Renders a partial MVC view to string. Use this method to render /// a partial view that doesn't merge with _Layout and doesn't fire /// _ViewStart. /// </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">Text writer to render view to</param> /// <param name="errorMessage">optional output parameter to receive an error message on failure</param> public static void RenderPartialView(string viewPath, TextWriter writer, object model = null, ControllerContext controllerContext = null) { ViewRenderer renderer = new ViewRenderer(controllerContext); renderer.RenderPartialView(viewPath, model, writer); }
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); } }