私はついにこれを行う方法を手に入れました。
実際、rotativaのメソッド "return new ViewAsPdf(model)"はHttpResponseStreamを返します。なかなかできないところ。ただし、カスタム属性を使用してアクションが実行されると、応答を変更/変更できます。アクションフィルターのOnResultExecuted()メソッドをオーバーライドできます。
コントローラーのアクション
[HttpGet]
[ActionDownload] //here a custom action filter added
public ActionResult DownloadDocument()
{
var htmlContent = "<h1>sachin Kumar</hi>";
var model = new PdfInfo {FtContent = htmlContent, FtName = "Populate Form"};
return new ViewAsPdf(model);
}
カスタムアクションフィルター:
public class ActionDownloadAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
//Add content-disposition header to response so that browser understand to download as an attachment.
filterContext.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" + "Report.pdf");
base.OnResultExecuted(filterContext);
}
}