title: How to Attribute encode a PartialView in MVC (Razor)
body: <p>I'm using PartialViews to store the HTML for a tooltip in my ASP.NET MVC application.  My initial thought was that Razor would automatically attribute encode anything sat between quotes in my HTML.  Unfortunately this doesn't appear to be the case and so my workaround for now is to use single quotation marks to encapsulate my PartialViews HTML.  As below:</p>
  
  <pre><code>&lt;div class="tooltip" title='@Html.Partial("_MyTooltipInAPartial")'&gt;Some content&lt;/div&gt;
  </code></pre>
  
  <p>This works just dandy but obviously I have problems if there are any single quotation marks within my PartialView.</p>
  
  <p>Does anyone know the proper approach to resolve this?  The closest I've got is the below:</p>
  
  <pre><code>&lt;div class="tooltip" title="@HttpUtility.HtmlAttributeEncode(Html.Partial("_MyTooltipInAPartial"))"&gt;Some content&lt;/div&gt;
  </code></pre>
  
  <p>Unfortunately this doesn't quite work because the output of a Partial is an MvcHtmlString rather than a straight string.</p>
  
  <p>Anyone got a better idea?</p>