Render view to a string

11 views
Skip to first unread message

Jon Kruger

unread,
Feb 20, 2009, 12:41:56 PM2/20/09
to mvccontrib-discuss
Is there any way in MVCContrib that I can render a view to a string
from inside a controller method? I can do it using the methods
outlined in these posts:

http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-2/#comment-785
http://stackoverflow.com/questions/483091/render-a-view-as-a-string

... but I was wondering if this is baked in MVCContrib by now.

Jon

Jeremy Skinner

unread,
Feb 20, 2009, 12:53:07 PM2/20/09
to mvccontri...@googlegroups.com
Since Preview 5 the IView interface's Render method can take a TextWriter to which the view can be rendered. 

Unfortunately, the WebFormViewEngine does not make use of this parameter due to limitations of the underlying webforms implementation. With other view engines you could pass a StringWriter to the view.Render method to capture the output, but with the WebForms view engine you're stuck with the BlockRenderer.

Jeremy

2009/2/20 Jon Kruger <krug...@gmail.com>
Reply all
Reply to author
Forward
0 new messages