<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: RenderPartial to String in ASP.NET MVC Beta</title>
	<atom:link href="http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/</link>
	<description></description>
	<lastBuildDate>Wed, 26 Jan 2011 18:41:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: xinqikan</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1364</link>
		<dc:creator>xinqikan</dc:creator>
		<pubDate>Wed, 17 Nov 2010 08:06:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-1364</guid>
		<description>Is ASP.NET MVC&#039;s FileStreamResult less efficient than writing directly to the Response Output Stream, or am I missing something?</description>
		<content:encoded><![CDATA[<p>Is ASP.NET MVC&#8217;s FileStreamResult less efficient than writing directly to the Response Output Stream, or am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Render a view as a string — HTMLCoderHelper.com</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1362</link>
		<dc:creator>Render a view as a string — HTMLCoderHelper.com</dc:creator>
		<pubDate>Sun, 14 Nov 2010 10:40:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-1362</guid>
		<description>[...] RenderPartial to String in ASP.NET MVC Beta If I use this example, I receive the &quot;Cannot redirect after HTTP headers have been sent.&quot;. [...]</description>
		<content:encoded><![CDATA[<p>[...] RenderPartial to String in ASP.NET MVC Beta If I use this example, I receive the &quot;Cannot redirect after HTTP headers have been sent.&quot;. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wessel</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1339</link>
		<dc:creator>Wessel</dc:creator>
		<pubDate>Fri, 20 Aug 2010 09:33:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-1339</guid>
		<description>The solution is very simple.

Create a new Viewclass based on the WebFormView, and use that as the ViewEnging for rendering (by returning this View in the CreatePartialView and CreateView methods of a custom WebFormViewEngine).

Override the Render method in your new Viewclass and create a new TextWriter.
Store the viewContent.Writer and set the viewContent.Writer to the newly created TextWriter.
Call MyBase.Render(viewContext,writer).
The writer is ignored, but you just changed the writer of the viewContext so any output goes there and not to the Response!

Restore the viewContext.Writer.

You can now use the content of the newly created TextWriter and do anything you like.
Finally write the changed content to the old viewContent.Writer (which writes to Response).

Performance does not degrade as far as I can tell and this works for partialrendering as well as for normal pages.
Basically for all view rendered output.

Example:

Imports System.IO

Public Class CustomRenderView
    Inherits WebFormView

    Public Sub New(ByVal viewPath As String)
        MyBase.New(viewPath)
    End Sub

    Public Sub New(ByVal viewPath As String, ByVal masterPath As String)
        MyBase.New(viewPath, masterPath)
    End Sub

    Public Overrides Sub Render(ByVal viewContext As System.Web.Mvc.ViewContext, ByVal writer As System.IO.TextWriter)
        Dim newWriter As TextWriter = New StringWriter()

        Dim oldWriter As TextWriter = viewContext.Writer
        viewContext.Writer = newWriter

        MyBase.Render(viewContext, newWriter) &#039;use newWriter in case MS changes its mind to ignore it...
        viewContext.Writer = oldWriter

        Dim pageSource As String = newWriter.ToString()
        &#039;do something with the generated output in pageSource

        &#039;write changed output to the original viewContext.Writer (goes to Response object)
        oldWriter.Write(pageSource)
    End Sub

End Class</description>
		<content:encoded><![CDATA[<p>The solution is very simple.</p>
<p>Create a new Viewclass based on the WebFormView, and use that as the ViewEnging for rendering (by returning this View in the CreatePartialView and CreateView methods of a custom WebFormViewEngine).</p>
<p>Override the Render method in your new Viewclass and create a new TextWriter.<br />
Store the viewContent.Writer and set the viewContent.Writer to the newly created TextWriter.<br />
Call MyBase.Render(viewContext,writer).<br />
The writer is ignored, but you just changed the writer of the viewContext so any output goes there and not to the Response!</p>
<p>Restore the viewContext.Writer.</p>
<p>You can now use the content of the newly created TextWriter and do anything you like.<br />
Finally write the changed content to the old viewContent.Writer (which writes to Response).</p>
<p>Performance does not degrade as far as I can tell and this works for partialrendering as well as for normal pages.<br />
Basically for all view rendered output.</p>
<p>Example:</p>
<p>Imports System.IO</p>
<p>Public Class CustomRenderView<br />
    Inherits WebFormView</p>
<p>    Public Sub New(ByVal viewPath As String)<br />
        MyBase.New(viewPath)<br />
    End Sub</p>
<p>    Public Sub New(ByVal viewPath As String, ByVal masterPath As String)<br />
        MyBase.New(viewPath, masterPath)<br />
    End Sub</p>
<p>    Public Overrides Sub Render(ByVal viewContext As System.Web.Mvc.ViewContext, ByVal writer As System.IO.TextWriter)<br />
        Dim newWriter As TextWriter = New StringWriter()</p>
<p>        Dim oldWriter As TextWriter = viewContext.Writer<br />
        viewContext.Writer = newWriter</p>
<p>        MyBase.Render(viewContext, newWriter) &#8216;use newWriter in case MS changes its mind to ignore it&#8230;<br />
        viewContext.Writer = oldWriter</p>
<p>        Dim pageSource As String = newWriter.ToString()<br />
        &#8216;do something with the generated output in pageSource</p>
<p>        &#8216;write changed output to the original viewContext.Writer (goes to Response object)<br />
        oldWriter.Write(pageSource)<br />
    End Sub</p>
<p>End Class</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1005</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Tue, 13 Oct 2009 00:35:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-1005</guid>
		<description>Hello all, I&#039;ve updated this post to link to a new article, which makes renderpartial to string substantially easier in ASP.NET MVC</description>
		<content:encoded><![CDATA[<p>Hello all, I&#8217;ve updated this post to link to a new article, which makes renderpartial to string substantially easier in ASP.NET MVC</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Atkinson</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-962</link>
		<dc:creator>Dan Atkinson</dc:creator>
		<pubDate>Fri, 07 Aug 2009 08:26:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-962</guid>
		<description>Lorenz,

If you look up at the comment on January 28th, you&#039;ll see that I mentioned this. :)

Thanks,

Dan (the guy who originally created the SO question!).</description>
		<content:encoded><![CDATA[<p>Lorenz,</p>
<p>If you look up at the comment on January 28th, you&#8217;ll see that I mentioned this. <img src='http://www.brightmix.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks,</p>
<p>Dan (the guy who originally created the SO question!).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lorenz Cuno Klopfenstein</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-961</link>
		<dc:creator>Lorenz Cuno Klopfenstein</dc:creator>
		<pubDate>Thu, 06 Aug 2009 20:47:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-961</guid>
		<description>Hello people,
I found a new solution that doesn&#039;t involve messing with the filters of the current HttpResponse and shouldn&#039;t have problems with ContentType and other headers (it isn&#039;t quite as elegant as Martin&#039;s solution, but it also works for views that inherit from ViewPage instead of UserControls only).
Here it is on StackOverflow: http://stackoverflow.com/questions/483091/render-a-view-as-a-string/1241257#1241257

Hope it helps. :) Greetings</description>
		<content:encoded><![CDATA[<p>Hello people,<br />
I found a new solution that doesn&#8217;t involve messing with the filters of the current HttpResponse and shouldn&#8217;t have problems with ContentType and other headers (it isn&#8217;t quite as elegant as Martin&#8217;s solution, but it also works for views that inherit from ViewPage instead of UserControls only).<br />
Here it is on StackOverflow: <a href="http://stackoverflow.com/questions/483091/render-a-view-as-a-string/1241257#1241257" rel="nofollow">http://stackoverflow.com/questions/483091/render-a-view-as-a-string/1241257#1241257</a></p>
<p>Hope it helps. <img src='http://www.brightmix.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Greetings</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-849</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Wed, 17 Jun 2009 21:37:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-849</guid>
		<description>Jon Kruger: My approach doenst have any problems with content-type.

Anyway, i just wanted to add that nesting the custom render partial works just fine (i use it for a email template service).

If you need to make the helpers work (html/ajax/url) remember to call InitHelpers() on the ViewPage (and add ViewContext / ControllerContext).</description>
		<content:encoded><![CDATA[<p>Jon Kruger: My approach doenst have any problems with content-type.</p>
<p>Anyway, i just wanted to add that nesting the custom render partial works just fine (i use it for a email template service).</p>
<p>If you need to make the helpers work (html/ajax/url) remember to call InitHelpers() on the ViewPage (and add ViewContext / ControllerContext).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Kruger</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-846</link>
		<dc:creator>Jon Kruger</dc:creator>
		<pubDate>Sun, 07 Jun 2009 02:59:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-846</guid>
		<description>I think I found a way around the limitation where you can&#039;t change the content type.  It seems to be working for me so far.

&lt;a href=&quot;http://jonkruger.com/blog/2009/06/06/aspnet-mvc-rendering-a-partial-view-to-a-string/&quot; rel=&quot;nofollow&quot;&gt;
http://jonkruger.com/blog/2009/06/06/aspnet-mvc-rendering-a-partial-view-to-a-string/&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>I think I found a way around the limitation where you can&#8217;t change the content type.  It seems to be working for me so far.</p>
<p><a href="http://jonkruger.com/blog/2009/06/06/aspnet-mvc-rendering-a-partial-view-to-a-string/" rel="nofollow"><br />
</a><a href="http://jonkruger.com/blog/2009/06/06/aspnet-mvc-rendering-a-partial-view-to-a-string/" rel="nofollow">http://jonkruger.com/blog/2009/06/06/aspnet-mvc-rendering-a-partial-view-to-a-string/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-842</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Tue, 26 May 2009 15:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-842</guid>
		<description>Thank You,Thank You,Thank You! This is exactly what I needed. I am returning a JSONResult now with the output from my Partial!</description>
		<content:encoded><![CDATA[<p>Thank You,Thank You,Thank You! This is exactly what I needed. I am returning a JSONResult now with the output from my Partial!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maico Tamayo</title>
		<link>http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-835</link>
		<dc:creator>Maico Tamayo</dc:creator>
		<pubDate>Mon, 11 May 2009 16:10:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com//2008/11/24/how-to-renderpartial-to-string-in-asp-net-mvc#comment-835</guid>
		<description>To Ozkan,  
 Sorry for my late reply, I was so busy with my work, we also experienced that same problem when our company migrated from mvc beta to 1.0, and we found out to prevent this error, you must really but viewData or at least instantiate it properly for your RenderPartialString method, I don&#039;t know your situation, but in our case it worked.. It seems working, maybe the MVC team is a little strict nowadays when it comes to rendering a page with a null viewdata,I really don&#039;t know.But I hope this helps you.</description>
		<content:encoded><![CDATA[<p>To Ozkan,<br />
 Sorry for my late reply, I was so busy with my work, we also experienced that same problem when our company migrated from mvc beta to 1.0, and we found out to prevent this error, you must really but viewData or at least instantiate it properly for your RenderPartialString method, I don&#8217;t know your situation, but in our case it worked.. It seems working, maybe the MVC team is a little strict nowadays when it comes to rendering a page with a null viewdata,I really don&#8217;t know.But I hope this helps you.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
