<?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</title>
	<atom:link href="http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/</link>
	<description></description>
	<lastBuildDate>Wed, 19 May 2010 19:42:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Kevin Craft</title>
		<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1299</link>
		<dc:creator>Kevin Craft</dc:creator>
		<pubDate>Sat, 15 May 2010 17:11:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com/?p=2894#comment-1299</guid>
		<description>I wrote a post that solves the same problem in a slightly different way. I dug into the ASP.NET MVC source and used the method they use. The Html and Ajax helpers work properly. You also don&#039;t have to provide the full path to the partial view&#039;s filename. You can use it just like the &quot;PartialView&quot; function in the controller. Check it out at &lt;a href=&quot;http://craftycode.wordpress.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/&quot; rel=&quot;nofollow&quot;&gt;http://craftycode.wordpress.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>I wrote a post that solves the same problem in a slightly different way. I dug into the ASP.NET MVC source and used the method they use. The Html and Ajax helpers work properly. You also don&#8217;t have to provide the full path to the partial view&#8217;s filename. You can use it just like the &#8220;PartialView&#8221; function in the controller. Check it out at <a href="http://craftycode.wordpress.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/" rel="nofollow">http://craftycode.wordpress.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua</title>
		<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1284</link>
		<dc:creator>Joshua</dc:creator>
		<pubDate>Thu, 25 Mar 2010 15:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com/?p=2894#comment-1284</guid>
		<description>I have implemented this solution, however, I am curious how we retrieve the data in the partial view?

Currently, I am casting the ViewData Objects in the partial view (not using a view model)



Unfortunately, ViewData seems to be empty when rendering.. No matter what I pass into RenderPartialToString as the viewData...

NE thoughts?</description>
		<content:encoded><![CDATA[<p>I have implemented this solution, however, I am curious how we retrieve the data in the partial view?</p>
<p>Currently, I am casting the ViewData Objects in the partial view (not using a view model)</p>
<p>Unfortunately, ViewData seems to be empty when rendering.. No matter what I pass into RenderPartialToString as the viewData&#8230;</p>
<p>NE thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bobasoft</title>
		<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1228</link>
		<dc:creator>Bobasoft</dc:creator>
		<pubDate>Sat, 09 Jan 2010 10:23:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com/?p=2894#comment-1228</guid>
		<description>when use ajax helper in partial view - will be crash. 

http://msug.vn.ua/blogs/bobasoft/archive/2010/01/07/render-partialview-to-string-asp-net-mvc.aspx - nicer solution</description>
		<content:encoded><![CDATA[<p>when use ajax helper in partial view &#8211; will be crash. </p>
<p><a href="http://msug.vn.ua/blogs/bobasoft/archive/2010/01/07/render-partialview-to-string-asp-net-mvc.aspx" rel="nofollow">http://msug.vn.ua/blogs/bobasoft/archive/2010/01/07/render-partialview-to-string-asp-net-mvc.aspx</a> &#8211; nicer solution</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Davis</title>
		<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1207</link>
		<dc:creator>Gary Davis</dc:creator>
		<pubDate>Fri, 04 Dec 2009 16:37:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com/?p=2894#comment-1207</guid>
		<description>Based on what I read in your reference, I made these changes to solve the trap:

&lt;code&gt;
public static string RenderPartialToString(this HtmlHelper htmlHelper, string controlName, object viewData)
{
  // Added Url to allow ascx to use Url.Action()
  var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
  // Added ViewContext to allow ascx to use Html helpers
  var vp = new ViewPage { ViewData = vd, ViewContext = htmlHelper.ViewContext, Url = urlHelper};
&lt;/code&gt;

Note this is an Html helper called with Html.RenderPartialToString(). If not, use these changes:

&lt;code&gt;
  var vc = new ViewContext();
  // Added Url to allow ascx to use Url.Action()
  var urlHelper = new UrlHelper(vc.RequestContext);
  // Added ViewContext to allow ascx to use Html helpers
  var vp = new ViewPage { ViewData = vd, ViewContext = vc, Url = urlHelper };
&lt;/code&gt;

Gary</description>
		<content:encoded><![CDATA[<p>Based on what I read in your reference, I made these changes to solve the trap:</p>
<p><code><br />
public static string RenderPartialToString(this HtmlHelper htmlHelper, string controlName, object viewData)<br />
{<br />
  // Added Url to allow ascx to use Url.Action()<br />
  var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);<br />
  // Added ViewContext to allow ascx to use Html helpers<br />
  var vp = new ViewPage { ViewData = vd, ViewContext = htmlHelper.ViewContext, Url = urlHelper};<br />
</code></p>
<p>Note this is an Html helper called with Html.RenderPartialToString(). If not, use these changes:</p>
<p><code><br />
  var vc = new ViewContext();<br />
  // Added Url to allow ascx to use Url.Action()<br />
  var urlHelper = new UrlHelper(vc.RequestContext);<br />
  // Added ViewContext to allow ascx to use Html helpers<br />
  var vp = new ViewPage { ViewData = vd, ViewContext = vc, Url = urlHelper };<br />
</code></p>
<p>Gary</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Davis</title>
		<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1206</link>
		<dc:creator>Gary Davis</dc:creator>
		<pubDate>Fri, 04 Dec 2009 16:05:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com/?p=2894#comment-1206</guid>
		<description>This worked nicely except when the ascx control used an Html helper (). Html was null causing a Null-ref trap. 

The trap did not occur if the control was referenced by Html.RenderPartial() instead of RenderPartialToString().

Gary</description>
		<content:encoded><![CDATA[<p>This worked nicely except when the ascx control used an Html helper (). Html was null causing a Null-ref trap. </p>
<p>The trap did not occur if the control was referenced by Html.RenderPartial() instead of RenderPartialToString().</p>
<p>Gary</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1122</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Wed, 28 Oct 2009 05:01:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com/?p=2894#comment-1122</guid>
		<description>When I tried to use this code I had to change this line:
&lt;code&gt;
ViewDataDictionary vd = new ViewDataDictionary(viewData);
&lt;/code&gt;

To:
&lt;code&gt;
ViewPage vp = new ViewPage { ViewData = (ViewDataDictionary)viewData };
&lt;/code&gt;

Not sure why but when I created the ViewDataDictionary object with the constructor I was losing all of viewData&#039;s parameters.</description>
		<content:encoded><![CDATA[<p>When I tried to use this code I had to change this line:<br />
<code><br />
ViewDataDictionary vd = new ViewDataDictionary(viewData);<br />
</code></p>
<p>To:<br />
<code><br />
ViewPage vp = new ViewPage { ViewData = (ViewDataDictionary)viewData };<br />
</code></p>
<p>Not sure why but when I created the ViewDataDictionary object with the constructor I was losing all of viewData&#8217;s parameters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1011</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Tue, 13 Oct 2009 15:01:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com/?p=2894#comment-1011</guid>
		<description>Hey Dan,

As far as I know, your point is quite valid. If you want to render an entire view to a string, the previous post will work and this one will not.

However, the idea behind RenderPartialToString, is geared at just that, rendering a partial view to a string.</description>
		<content:encoded><![CDATA[<p>Hey Dan,</p>
<p>As far as I know, your point is quite valid. If you want to render an entire view to a string, the previous post will work and this one will not.</p>
<p>However, the idea behind RenderPartialToString, is geared at just that, rendering a partial view to a string.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Atkinson</title>
		<link>http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/comment-page-1/#comment-1010</link>
		<dc:creator>Dan Atkinson</dc:creator>
		<pubDate>Tue, 13 Oct 2009 11:23:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.brightmix.com/?p=2894#comment-1010</guid>
		<description>You link from your last blog post, but this isn&#039;t the same as rendering a view to a string.

This is just rendering a partial as views don&#039;t extend Control.

So, if you wanted to actually generate an entire view into a string, you&#039;d still need to use the old method. That or rework your views to be partials instead...</description>
		<content:encoded><![CDATA[<p>You link from your last blog post, but this isn&#8217;t the same as rendering a view to a string.</p>
<p>This is just rendering a partial as views don&#8217;t extend Control.</p>
<p>So, if you wanted to actually generate an entire view into a string, you&#8217;d still need to use the old method. That or rework your views to be partials instead&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 2.297 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-05-20 04:13:47 -->
