title: Understanding asp.net mvc IView and IView.Render
body: <p>I'm trying to devise a method of doing VERY simple asp.net mvc plugins but mostly I'm trying to understand how view rendering works.</p>
  
  <p>I've distilled my problem down to this</p>
  
  <pre><code>public class CustomView : IView
  {
      public void Render(ViewContext viewContext, TextWriter writer)
      {
          writer.Write( /* string to render */);
      }
  }
  </code></pre>
  
  <p>Now, within that write method I can render any string to the view but when I put a line of code in there
  wrapped with &lt;% %> it renders the code to the view literally rather than parsing it and executing it.
  I've tried adding things like &lt;% @Page ... to the beginning of the string and it just renders that literally as well.</p>
  
  <p>Among many attempts I'm currently calling it this way within a controller action:</p>
  
  <pre><code>...
  CustomView customView = new CustomView();
  
  ViewResult result = new ViewResult();
  result.View = customView;
  result.ViewName = "Index.aspx";
  result.MasterName = "";
  return result;
  </code></pre>
  
  <p>What am I missing or doing wrong that this won't work?  The ViewResult seems to have the WebFormViewEngine in its ViewEngines collection.</p>
  
  <p>I just want to understand this and after stripping it down to what I think should be the minimum it doesn't behave as I think it should. I'm guessing some other part of the machinery is involved/missing but I can't figure out what.</p>