title: Render partial view to string MVC4
body: <p>I am using the following to render a partial view to a string...</p>
  
  <pre><code>        protected string RenderPartialViewToString(string viewName, object model)
      {
          if (string.IsNullOrEmpty(viewName))
              viewName = ControllerContext.RouteData.GetRequiredString("action");
  
          ViewData.Model = model;
  
          using (var sw = new StringWriter())
          {
              ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
              var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
              viewResult.View.Render(viewContext, sw);
  
              return sw.GetStringBuilder().ToString();
          }
      }
  </code></pre>
  
  <p>However it returns the html with strange tags like this below... (I have included a small section as its a big view)</p>
  
  <pre><code>&lt;$A$&gt;&lt;div&lt;/$A$&gt;&lt;$B$&gt; class="modal hide fade"&lt;/$B$&gt;&lt;$C$&gt; id="dialog"&lt;/$C$&gt;&lt;$D$&gt; 
  </code></pre>
  
  <p>This happens throughout the HTML. This section should look like this...</p>
  
  <pre><code>&lt;div class="modal hide fade" id="dialog" style="display: none;"&gt;
  </code></pre>