Skip to main content
All docs
V26.1
  • How to Use Parameter Values from the Standalone Report Parameters Panel (ASP.NET Core App)

    • 3 minutes to read

    The Standalone Report Parameters Panel allows the user to specify values for report parameters. Call the SerializeParametersState client method to access parameter values. This method returns a string of serialized parameters. On the server, call the IReportParametersSerializer.ApplyParametersStateAsync method to apply the parameters to a report instance.

    This example adds an Export button to the Standalone Report Parameters Panel. When a user clicks the button, the Standalone Report Parameters Panel sends parameter values to the server, and the controller action processes them. The ExportWithParameters action uses the IReportParametersSerializer.ApplyParametersStateAsync method to apply parameter values to the report instance. Subsequently, the ExportToPdf(String, PdfExportOptions) method exports the report to a PDF file.

    Standalone Report Parameters Panel with Buttons

    Prerequisites

    This help topic is based on an application created from the ASP.NET Core Web App (Model-View-Controller) project template in Microsoft Visual Studio. This application integrates the Standalone Report Parameters Panel component as described in the following help topic: Standalone Report Parameters Panel in ASP.NET Core Applications.

    Handle the BeforeRender Event

    The BeforeRender event handler adds an Export button to the Parameters Panel and defines a function to handle the button’s onClick event. This function validates parameter values, serializes the parameters, and uses the jQuery ajax callback function to send the parameter information and a report identifier to the server.

    The following code example handles the BeforeRender event of the Standalone Report Parameters Panel component:

    function OnBeforeRender(sender, e) {
        const panel = sender.GetParametersModel();
        panel.buttons.push({
            onClick: async (args) => {
                const validation = args.validationGroup.validate();
                const result = validation.status === 'pending' ? await validation.complete : validation;
                if (!result.isValid)
                    return;
                const data = sender.SerializeParametersState();
                $.ajax({
                    url: "ExportWithParameters",
                    method: 'POST',
                    data: { serializedParameters: data, reportUrl: "@Model.ReportInfo.ReportUrl" }
                }).then(response => {
                    alert(response.message);
                });
            },
            text: 'Export'
        });
        panel.showButtons = true;
    }
    

    Important

    Validate parameter values before you call SerializeParametersState. If a value is invalid, the method returns the last valid value.

    The following code snippet specifies the OnBeforeRender function as the BeforeRender event handler:

    @{
        var panelRender = Html.DevExpress().ReportParametersPanel("ParametersPanel")
            .Height("100%")
            .Width("750px")
            .ClientSideEvents((configure) =>
            {
                configure.BeforeRender("OnBeforeRender");
            })
            .Bind(Model);
        @panelRender.RenderHtml()
    }
    

    Implement the Controller Action

    When the user clicks the Export button, the panel sends a request to the controller action, and the server sends the resulting PDF file to the client.

    The client sends parameter data to the ExportWithParameters controller action. Call the ApplyParametersStateAsync method in the action code to apply parameters to the report.

    Once the report instance has all the necessary parameter values, it can generate a document. Call the ExportToPdf method to create a PDF document from the report.

    using DevExpress.XtraReports.Web.ParametersPanel;
    using Microsoft.AspNetCore.Mvc;
    // ...
        public async Task<IActionResult> ExportWithParameters(
        [FromServices] IReportParametersSerializer reportParametersSerializer,
        [FromServices] IWebHostEnvironment env,
        [FromForm] string serializedParameters,
        [FromForm] string reportUrl) {
            var report = await reportParametersSerializer.ApplyParametersStateAsync(reportUrl,
                serializedParameters);
            string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
            string fileDir = Path.Combine(env.ContentRootPath,"Reports");
            if (!Directory.Exists(fileDir)) {
                Directory.CreateDirectory(fileDir);
            }
            report.ExportToPdf(Path.Combine(fileDir,$"{reportUrl}_{timestamp}.pdf"));
            return Ok(new { message = "The report "+ " is exported successfully to "+ fileDir });
        }
    

    The controller action saves the PDF file to the Reports folder in the project.

    Next Steps

    You can modify the controller action to export a report to different formats or email the exported document. For additional information, review the following help topic: Export Reports.

    Use the DevExpress Office File API to edit the exported document on a server.

    You can implement an Azure function or an AWS Lambda function to integrate DevExpress Reports in your cloud application. For additional information, review the following help topics: