Exemplo n.º 1
0
        /// <summary>
        /// Renders the specified view using MVC Razor.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="model">The model.</param>
        /// <returns>The view content.</returns>
        /// <exception cref="System.ArgumentNullException">view</exception>
        protected HttpResponseMessage View(string view, object model = null)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            var html = ViewRenderer.RenderView(view, null, fakeController.ControllerContext);

            return(new HttpResponseMessage()
            {
                Content = new StringContent(html, Encoding.UTF8, "text/html")
            });
        }
Exemplo n.º 2
0
 /// <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="errorMessage">optional output parameter to receive an error message on failure</param>
 /// <returns>String of the rendered view or null on error</returns>
 public static string RenderPartialView(string viewPath, object model,
                                        ControllerContext controllerContext,
                                        out string errorMessage)
 {
     errorMessage = null;
     try
     {
         var renderer = new ViewRenderer(controllerContext);
         return(renderer.RenderPartialView(viewPath, model));
     }
     catch (Exception ex)
     {
         errorMessage = ex.GetBaseException().Message;
     }
     return(null);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomApiControllerBase"/> class.
 /// </summary>
 protected CustomApiControllerBase()
 {
     fakeController = ViewRenderer.CreateController <ViewRenderer.FakeController>();
 }