title: Determine context of RenderView in MVC3
body: <p>I want to manipulate HTML using a custom view engine like this:</p>
  
  <pre><code>protected override void RenderView(ViewContext viewContext, TextWriter writer, object instance)
  {
      if (viewContext.Controller is MyController)
      {
         .. alter the html then write to writer
      } else {
          base.RenderView(viewContext, writer, instance);
      }
  }
  </code></pre>
  
  <p><code>RenderView</code> gets called for the view and each partial view, but I can't figure out a reliable way to determine whether it's rendering the outer view or a partial view. </p>
  
  <p>The type of the <code>writer</code> object is <code>HttpWriter</code> for a partial view and <code>StringWriter</code> for the outer view. This seems like a bad way to test it, but so far it's the only concrete thing I can find </p>
  
  <p>The <code>instance</code> tells me the view or partial view name, but checking a string to see if I'm rendering a partial view or not seems brittle.</p>
  
  <p>Is there any more direct way to determine if it's a partial view or not?</p>