title: Convert asp.net webforms logic to asp.net MVC
body: <p>I had this code in an old asp.net webforms app to take a <code>MemoryStream</code> and pass it as the Response showing a PDF as the response. I am now working with an asp.net MVC application and looking to do this this same thing, but how should I go about showing the <code>MemoryStream</code> as  PDF using MVC?</p>
  
  <p>Here's my asp.net webforms code:</p>
  
  <pre><code>    private void ShowPDF(MemoryStream ms)
      {
          try
          {
              //get byte array of pdf in memory
              byte[] fileArray = ms.ToArray();
              //send file to the user
              Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
              Page.Response.Buffer = true;
              Response.Clear();
              Response.ClearContent();
              Response.ClearHeaders();
              Response.Charset = string.Empty;
              Response.ContentType = "application/pdf";
              Response.AddHeader("content-length", fileArray.Length.ToString());
              Response.AddHeader("Content-Disposition", "attachment;filename=TID.pdf;");
              Response.BinaryWrite(fileArray);
              Response.Flush();
              Response.Close();
          }
          catch
          {
             // and boom goes the dynamite...
          }
      }
  </code></pre>