RenderPartialToString missing in ASP.NET MVC

If I had to pick the most important feature that is missing from ASP.NET MVC it would be RenderPartialToString. This method should render a partial view to a string and not to internal result. Why? Simple, when you have to do with AJAX and partial updates it is convenient to pack one ore more partial results into a JSON among with other related data.

So, RenderPartialToString would be my most important feature missing in ASP.NET MVC. Luckily ASP.NET MVC is very extensible and Kevin hacked up a solution. Make sure you also read the comments, specially one from Jon Kruger (where he fix a bug or two) and one from Kyle Simpson (where he describes a workaround around setting a proper content type).

Implemented all the code and fixes mentioned above I am able to return a JSON object containing more than one partial result and related data. But still, this looks like a hack and performance might be a problem (or not, no idea – did anybody check it out?). Anyway, I really hope that we’ll see RenderPartialToString in a future version or, even better, in a service pack – as soon as possible that is.

And of course, I've enhanced my strong typed views template with Render[PartialView]ToString strong typed methods as well.

Leave a Reply