From 42cc58b53c9c34a5da9898f356924eecc8047e21 Mon Sep 17 00:00:00 2001 From: Robas Date: Wed, 27 Sep 2017 11:37:37 +0200 Subject: [PATCH] Added content disposition parameter --- Rotativa/AsResultBase.cs | 9 ++++++++- Rotativa/Options/Enums.cs | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Rotativa/AsResultBase.cs b/Rotativa/AsResultBase.cs index 0c66a98..0bf12eb 100644 --- a/Rotativa/AsResultBase.cs +++ b/Rotativa/AsResultBase.cs @@ -102,6 +102,8 @@ public string CookieName [Obsolete(@"Use BuildFile(this.ControllerContext) method instead and use the resulting binary data to do what needed.")] public string SaveOnServerPath { get; set; } + public ContentDisposition ContentDisposition { get; set; } + protected abstract string GetUrl(ControllerContext context); /// @@ -218,8 +220,13 @@ protected HttpResponseBase PrepareResponse(HttpResponseBase response) response.ContentType = this.GetContentType(); if (!String.IsNullOrEmpty(this.FileName)) - response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", SanitizeFileName(this.FileName))); + { + var contentDisposition = this.ContentDisposition == ContentDisposition.Attachment + ? "attachment" + : "inline"; + response.AddHeader("Content-Disposition", string.Format("{0}; filename=\"{1}\"", contentDisposition, SanitizeFileName(this.FileName))); + } response.AddHeader("Content-Type", this.GetContentType()); return response; diff --git a/Rotativa/Options/Enums.cs b/Rotativa/Options/Enums.cs index 4be1ee1..a016908 100644 --- a/Rotativa/Options/Enums.cs +++ b/Rotativa/Options/Enums.cs @@ -174,4 +174,10 @@ public enum ImageFormat jpeg, png } + + public enum ContentDisposition + { + Attachment = 0, // this is the default + Inline + } }