I've created a PdfActionResult class as follows:
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);
}
}
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.