title: How to return xml as UTF-8 instead of UTF-16
body: <p>I am using a routine that serializes <code>&lt;T&gt;</code>. It works, but when downloaded to the browser I see a blank page. I can view the page source or open the download in a text editor and I see the xml, but it is in UTF-16 which I think is why browser pages show blank?</p>
  
  <p><strong>How do I modify my serializer routine to return UTF-8 instead of UTF-16?</strong></p>
  
  <p>The XML source returned:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;string&gt;January&lt;/string&gt;
    &lt;string&gt;February&lt;/string&gt;
    &lt;string&gt;March&lt;/string&gt;
    &lt;string&gt;April&lt;/string&gt;
    &lt;string&gt;May&lt;/string&gt;
    &lt;string&gt;June&lt;/string&gt;
    &lt;string&gt;July&lt;/string&gt;
    &lt;string&gt;August&lt;/string&gt;
    &lt;string&gt;September&lt;/string&gt;
    &lt;string&gt;October&lt;/string&gt;
    &lt;string&gt;November&lt;/string&gt;
    &lt;string&gt;December&lt;/string&gt;
    &lt;string /&gt;
  &lt;/ArrayOfString&gt;
  </code></pre>
  
  <p>An example call to the serializer:</p>
  
  <pre><code>DateTimeFormatInfo dateTimeFormatInfo = new DateTimeFormatInfo();
  var months = dateTimeFormatInfo.MonthNames.ToList();
  
  string SelectionId = "1234567890";
  
  return new XmlResult&lt;List&lt;string&gt;&gt;(SelectionId)
  {
      Data = months
  };
  </code></pre>
  
  <p>The Serializer:</p>
  
  <pre><code>public class XmlResult&lt;T&gt; : ActionResult
  {
      private string filename = DateTime.Now.ToString("ddmmyyyyhhss");
  
      public T Data { private get; set; }
  
      public XmlResult(string selectionId = "")
      {
          if (selectionId != "")
          {
              filename = selectionId;
          }
      }
  
      public override void ExecuteResult(ControllerContext context)
      {
          HttpContextBase httpContextBase = context.HttpContext;
          httpContextBase.Response.Buffer = true;
          httpContextBase.Response.Clear();
  
          httpContextBase.Response.AddHeader("content-disposition", "attachment; filename=" + filename + ".xml");
          httpContextBase.Response.ContentType = "text/xml";
  
          using (StringWriter writer = new StringWriter())
          {
              XmlSerializer xml = new XmlSerializer(typeof(T));
              xml.Serialize(writer, Data);
              httpContextBase.Response.Write(writer);
          }
      }
  }
  </code></pre>