asp.net mvc 1.0 - how to render a partial view as a string

Posted by Chev on Stack Overflow See other posts from Stack Overflow or by Chev
Published on 2010-04-11T11:07:44Z Indexed on 2010/04/11 11:13 UTC
Read the original article Hit count: 334

Filed under:

Hi There

I need to render a partial view to a string within a controller action. I have the following sample code, but the ControllerContext.ParentActionViewContext does not seem to exist in mvc 1.0

            // Get the IView of the PartialView object.
            var view = PartialView("MyPartialView").View;

            // Initialize a StringWriter for rendering the output.
            var writer = new StringWriter();

            // Do the actual rendering.
            view.Render(ControllerContext.ParentActionViewContext, writer);

Any tips greatly appreciated.

© Stack Overflow or respective owner

Related posts about asp.net-mvc