title: How to download a pdf from a mvc partial view?
body: <p>I've created a PdfActionResult class as follows:</p>
  
  <pre><code>public class PdfActionResult : ActionResult
  {
      public byte[] FileContents { get; set; }
      public string FileName { get; set; }
  
  
      public override void ExecuteResult(ControllerContext context)
      {
          var cd = new System.Net.Mime.ContentDisposition()
                       {
                          FileName = FileName,
                          Inline = false,
                       };
  
          context.HttpContext.Response.Buffer = true;
          context.HttpContext.Response.Clear();
          context.HttpContext.Response.AppendHeader("Content-Disposition", cd.ToString());
          context.HttpContext.Response.ContentType = "application/pdf";
          context.HttpContext.Response.BinaryWrite(FileContents);
      }
  
  }
  </code></pre>
  
  <p>I have a controller method that returns a PdfActionResult. This works fine when called from within a view but it fails when called from a partial view. My guess is that it has something to do with the Controller context. Any help would be appreciated. Thanks.</p>