I have tried to implement simple ViewPage caching with ASP.NET MVC, however I cannot get the page to render correctly into a custom HtmlTextWriter when it has a master page.
I have tried overriding Render. If I simply call the base implementation, then everything renders correctly. If I render to my own writer and then write that string, then the page contents get scrambled.
Imports System.IO
Public Class CachedViewPage
Inherits System.Web.Mvc.ViewPage
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
'MyBase.Render(writer)
'Return
Dim stringView As String
Using sw As New StringWriter
Using w As New HtmlTextWriter(sw)
MyBase.Render(w)
End Using
stringView = sw.ToString()
End Using
writer.Write(stringView)
End Sub
End Class
It would seem that there is a tie between the MasterPage, the ViewPage, and the HtmlTextWriter.
How should I properly render this ViewPage to a string?