title: Render View programmatically into a string
body: <p>I would like to get the html code a view would generate in a string, modify it in my controller, then add it to my JsonResult.</p>
  
  <p>I found code that would do what i'm talking about from a partial. I would like to do it from an aspx View though.</p>
  
  <p>-- Extra explanation:</p>
  
  <p>Let's say I have a page Frame.aspx that /Controller/Frame will return</p>
  
  <p>I would like to get my hand on the response before it out so I can to wrap it with jsonp.
  I do not wish to edit the return result in code every time, this is why I want to load the view programmatically.</p>
  
  <p>/Controller/Frame currently returns Frame.aspx's content: <code>&lt;html&gt;&lt;body&gt;hello&lt;/body&gt;&lt;/html&gt;</code></p>
  
  <p>Let's say there's a function that renders a view in a string builder</p>
  
  <pre><code>StringBuilder sb = new StringBuilder();
  RenderView(sb, "Frame");
  </code></pre>
  
  <p>now take sb and wrap it with jsonp:</p>
  
  <pre><code>public JsonResult Frame(string callback)
  {
       StringBuilder sb = new StringBuilder();
       RenderView(sb, "Frame");
  
       return new JsonResult
       {
           Data = "(function() { " + callback + "(" +  clientResponse + "); })();"
           ,
           JsonRequestBehavior = JsonRequestBehavior.AllowGet
       };
  }
  </code></pre>