diff --git a/AlanJuden.MvcReportViewer.NetCore/CoreHtmlHelpers.cs b/AlanJuden.MvcReportViewer.NetCore/CoreHtmlHelpers.cs index a411343..76f005e 100644 --- a/AlanJuden.MvcReportViewer.NetCore/CoreHtmlHelpers.cs +++ b/AlanJuden.MvcReportViewer.NetCore/CoreHtmlHelpers.cs @@ -69,6 +69,8 @@ public static HtmlString RenderReportViewer(this IHtmlHelper helper, ReportViewe } } + sb.AppendLine($" "); + sb.AppendLine(" "); } @@ -82,17 +84,21 @@ public static HtmlString RenderReportViewer(this IHtmlHelper helper, ReportViewe sb.AppendLine("
"); sb.AppendLine("
"); sb.AppendLine("
"); - sb.AppendLine("
"); - sb.AppendLine($" "); - sb.AppendLine($" "); - sb.AppendLine("
"); - sb.AppendLine("
"); - sb.AppendLine($" of {contentData.TotalPages}"); - sb.AppendLine("
"); - sb.AppendLine("
"); - sb.AppendLine($" "); - sb.AppendLine($" "); - sb.AppendLine("
"); + + if (model.EnablePaging) + { + sb.AppendLine("
"); + sb.AppendLine($" "); + sb.AppendLine($" "); + sb.AppendLine("
"); + sb.AppendLine("
"); + sb.AppendLine($" of {contentData.TotalPages}"); + sb.AppendLine("
"); + sb.AppendLine("
"); + sb.AppendLine($" "); + sb.AppendLine($" "); + sb.AppendLine("
"); + } sb.AppendLine("
"); sb.AppendLine(" "); sb.AppendLine($" "); diff --git a/AlanJuden.MvcReportViewer.NetCore/ReportController.cs b/AlanJuden.MvcReportViewer.NetCore/ReportController.cs index 1994041..db77389 100644 --- a/AlanJuden.MvcReportViewer.NetCore/ReportController.cs +++ b/AlanJuden.MvcReportViewer.NetCore/ReportController.cs @@ -203,6 +203,16 @@ protected ReportViewerModel GetReportViewerModel(HttpRequest request) var model = new ReportViewerModel(); model.AjaxLoadInitialReport = this.AjaxLoadInitialReport; model.Credentials = this.NetworkCredentials; + + var enablePagingResult = _getRequestValue(request, "ReportViewerEnablePaging"); + if (enablePagingResult.HasValue()) + { + model.EnablePaging = enablePagingResult.ToBoolean(); + } + else + { + model.EnablePaging = true; + } model.Encoding = this.Encoding; model.ServerUrl = this.ReportServerUrl; model.ReportImagePath = this.ReportImagePath; @@ -211,5 +221,31 @@ protected ReportViewerModel GetReportViewerModel(HttpRequest request) return model; } + + private string _getRequestValue(HttpRequest request, string key) + { + if (request.Query != null && request.Query.Keys != null && request.Query.Keys.Contains(key)) + { + var values = request.Query[key].ToSafeString().Split(','); + if (values != null && values.Count() > 0) + { + return values[0].ToSafeString(); + } + } + + try + { + if (request.Form != null && request.Form.Keys != null && request.Form.Keys.Contains(key)) + { + return request.Form[key].ToSafeString(); + } + } + catch + { + //No need to throw errors, just no Form was passed in and it's unhappy about that + } + + return String.Empty; + } } } diff --git a/AlanJuden.MvcReportViewer.NetCore/ReportServiceHelpers.cs b/AlanJuden.MvcReportViewer.NetCore/ReportServiceHelpers.cs index b9e664b..c7c7831 100644 --- a/AlanJuden.MvcReportViewer.NetCore/ReportServiceHelpers.cs +++ b/AlanJuden.MvcReportViewer.NetCore/ReportServiceHelpers.cs @@ -82,7 +82,14 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s var deviceInfo = $"{outputFormat}{encodingFormat}False{htmlFragment}"; if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0) { - deviceInfo = $"{outputFormat}False{htmlFragment}
{startPage}
"; + if (model.EnablePaging) + { + deviceInfo = $"{outputFormat}False{htmlFragment}
{startPage}
"; + } + else + { + deviceInfo = $"{outputFormat}False{htmlFragment}"; + } } var reportParameters = new List(); @@ -124,18 +131,34 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s var executionParameterResult = service.SetReportParameters(executionInfo.ExecutionID, reportParameters.ToArray(), "en-us").Result; - var renderRequest = new ReportServiceExecution.Render2Request(format, deviceInfo, ReportServiceExecution.PageCountMode.Actual); - var result = service.Render2(executionInfo.ExecutionID, renderRequest).Result; + if (model.EnablePaging) + { + var renderRequest = new ReportServiceExecution.Render2Request(format, deviceInfo, ReportServiceExecution.PageCountMode.Actual); + var result = service.Render2(executionInfo.ExecutionID, renderRequest).Result; - extension = result.Extension; - mimeType = result.MimeType; - encoding = result.Encoding; - warnings = result.Warnings; - streamIDs = result.StreamIds; + extension = result.Extension; + mimeType = result.MimeType; + encoding = result.Encoding; + warnings = result.Warnings; + streamIDs = result.StreamIds; - executionInfo = service.GetExecutionInfo(executionHeader.ExecutionID).Result; + exportResult.ReportData = result.Result; + } + else + { + var renderRequest = new ReportServiceExecution.RenderRequest(format, deviceInfo); + var result = service.Render(executionInfo.ExecutionID, renderRequest).Result; + + extension = result.Extension; + mimeType = result.MimeType; + encoding = result.Encoding; + warnings = result.Warnings; + streamIDs = result.StreamIds; - exportResult.ReportData = result.Result; + exportResult.ReportData = result.Result; + } + + executionInfo = service.GetExecutionInfo(executionHeader.ExecutionID).Result; } catch (Exception ex) { diff --git a/AlanJuden.MvcReportViewer.NetCore/ReportViewerModel.cs b/AlanJuden.MvcReportViewer.NetCore/ReportViewerModel.cs index ad9bbdd..58e2d3a 100644 --- a/AlanJuden.MvcReportViewer.NetCore/ReportViewerModel.cs +++ b/AlanJuden.MvcReportViewer.NetCore/ReportViewerModel.cs @@ -48,6 +48,10 @@ public class ReportViewerModel /// This indicates whether or not the report will be preloaded when the page loads initially or if it will be an ajax request. /// public bool AjaxLoadInitialReport { get; set; } + /// + /// Setting this to 'true' enables the paging control and renders a single page at a time. Setting this to 'false' removes the paging control and shows all pages at once. + /// + public bool EnablePaging { get; set; } public ReportViewerModel() { diff --git a/AlanJuden.MvcReportViewer.NetCore/TypeExtensions.cs b/AlanJuden.MvcReportViewer.NetCore/TypeExtensions.cs index baf5674..00168aa 100644 --- a/AlanJuden.MvcReportViewer.NetCore/TypeExtensions.cs +++ b/AlanJuden.MvcReportViewer.NetCore/TypeExtensions.cs @@ -149,12 +149,12 @@ public static List ToStringList(this string data, string[] separators) public static string HtmlEncode(this string text) { - return System.Net.WebUtility.HtmlEncode(text.ToSafeString()); + return System.Text.Encodings.Web.HtmlEncoder.Default.Encode(text.ToSafeString()); } public static string UrlEncode(this string text) { - return System.Net.WebUtility.UrlEncode(text.ToSafeString()); + return System.Text.Encodings.Web.UrlEncoder.Default.Encode(text.ToSafeString()); } public static string HtmlDecode(this string text) diff --git a/AlanJuden.MvcReportViewer/HtmlHelperExtensions.cs b/AlanJuden.MvcReportViewer/HtmlHelperExtensions.cs index 58c74ce..3947575 100644 --- a/AlanJuden.MvcReportViewer/HtmlHelperExtensions.cs +++ b/AlanJuden.MvcReportViewer/HtmlHelperExtensions.cs @@ -66,6 +66,8 @@ public static MvcHtmlString RenderReportViewer(this HtmlHelper helper, ReportVie } } + sb.AppendLine($" "); + sb.AppendLine("
"); } @@ -79,17 +81,22 @@ public static MvcHtmlString RenderReportViewer(this HtmlHelper helper, ReportVie sb.AppendLine("
"); sb.AppendLine("
"); sb.AppendLine("
"); - sb.AppendLine("
"); - sb.AppendLine($" "); - sb.AppendLine($" "); - sb.AppendLine("
"); - sb.AppendLine("
"); - sb.AppendLine($" of {contentData.TotalPages}"); - sb.AppendLine("
"); - sb.AppendLine("
"); - sb.AppendLine($" "); - sb.AppendLine($" "); - sb.AppendLine("
"); + + if (model.EnablePaging) + { + sb.AppendLine("
"); + sb.AppendLine($" "); + sb.AppendLine($" "); + sb.AppendLine("
"); + sb.AppendLine("
"); + sb.AppendLine($" of {contentData.TotalPages}"); + sb.AppendLine("
"); + sb.AppendLine("
"); + sb.AppendLine($" "); + sb.AppendLine($" "); + sb.AppendLine("
"); + } + sb.AppendLine("
"); sb.AppendLine(" "); sb.AppendLine($" "); diff --git a/AlanJuden.MvcReportViewer/ReportController.cs b/AlanJuden.MvcReportViewer/ReportController.cs index e9887e3..21bc84c 100644 --- a/AlanJuden.MvcReportViewer/ReportController.cs +++ b/AlanJuden.MvcReportViewer/ReportController.cs @@ -1,4 +1,5 @@ -using System.Web; +using System; +using System.Web; using System.Web.Mvc; namespace AlanJuden.MvcReportViewer @@ -192,6 +193,17 @@ protected ReportViewerModel GetReportViewerModel(HttpRequestBase request) var model = new ReportViewerModel(); model.AjaxLoadInitialReport = this.AjaxLoadInitialReport; model.Credentials = this.NetworkCredentials; + + var enablePagingResult = _getRequestValue(request, "ReportViewerEnablePaging"); + if (enablePagingResult.HasValue()) + { + model.EnablePaging = enablePagingResult.ToBoolean(); + } + else + { + model.EnablePaging = true; + } + model.Encoding = this.Encoding; model.ServerUrl = this.ReportServerUrl; model.ReportImagePath = this.ReportImagePath; @@ -200,5 +212,28 @@ protected ReportViewerModel GetReportViewerModel(HttpRequestBase request) return model; } + private string _getRequestValue(HttpRequestBase request, string key) + { + var values = request.QueryString.GetValues(key); + if (values != null && values.Length > 0) + { + return values[0].ToSafeString(); + } + + try + { + if (request.Form != null && request.Form.Keys != null && request.Form[key] != null) + { + return request.Form[key].ToSafeString(); + } + } + catch + { + //No need to throw errors, just no Form was passed in and it's unhappy about that + } + + return String.Empty; + } + } } \ No newline at end of file diff --git a/AlanJuden.MvcReportViewer/ReportServiceHelpers.cs b/AlanJuden.MvcReportViewer/ReportServiceHelpers.cs index dcef415..1057619 100644 --- a/AlanJuden.MvcReportViewer/ReportServiceHelpers.cs +++ b/AlanJuden.MvcReportViewer/ReportServiceHelpers.cs @@ -54,7 +54,14 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s var deviceInfo = $"{outputFormat}False{htmlFragment}"; if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0) { - deviceInfo = $"{outputFormat}{encodingFormat}False{htmlFragment}
{startPage}
"; + if (model.EnablePaging) + { + deviceInfo = $"{outputFormat}{encodingFormat}False{htmlFragment}
{startPage}
"; + } + else + { + deviceInfo = $"{outputFormat}{encodingFormat}False{htmlFragment}"; + } } var reportParameters = new List(); @@ -95,11 +102,20 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s executionInfo = service.LoadReport(model.ReportPath, historyID); service.SetExecutionParameters(reportParameters.ToArray(), "en-us"); - var result = service.Render2(format, deviceInfo, ReportServiceExecution.PageCountMode.Actual, out extension, out mimeType, out encoding, out warnings, out streamIDs); + if (model.EnablePaging) + { + var result = service.Render2(format, deviceInfo, ReportServiceExecution.PageCountMode.Actual, out extension, out mimeType, out encoding, out warnings, out streamIDs); - executionInfo = service.GetExecutionInfo(); + exportResult.ReportData = result; + } + else + { + var result = service.Render(format, deviceInfo, out extension, out mimeType, out encoding, out warnings, out streamIDs); - exportResult.ReportData = result; + exportResult.ReportData = result; + } + + executionInfo = service.GetExecutionInfo(); } catch (Exception ex) { diff --git a/AlanJuden.MvcReportViewer/ReportViewerModel.cs b/AlanJuden.MvcReportViewer/ReportViewerModel.cs index adf3b8e..7f1ebbb 100644 --- a/AlanJuden.MvcReportViewer/ReportViewerModel.cs +++ b/AlanJuden.MvcReportViewer/ReportViewerModel.cs @@ -48,6 +48,11 @@ public class ReportViewerModel /// public bool AjaxLoadInitialReport { get; set; } + /// + /// Setting this to 'true' enables the paging control and renders a single page at a time. Setting this to 'false' removes the paging control and shows all pages at once. + /// + public bool EnablePaging { get; set; } + public ReportViewerModel() { this.Parameters = new Dictionary();