Back to Devexpress

IReportJsonSerializer Interface

xtrareports-devexpress-dot-xtrareports-dot-web-dot-reportdesigner-dot-services-e7765150.md

latest2.8 KB
Original Source

IReportJsonSerializer Interface

A service that serializes a report to JSON and deserializes JSON to report.

Namespace : DevExpress.XtraReports.Web.ReportDesigner.Services

Assembly : DevExpress.XtraReports.v25.2.Web.dll

NuGet Package : DevExpress.Web.Reporting.Common

Declaration

csharp
public interface IReportJsonSerializer
vb
Public Interface IReportJsonSerializer

Remarks

The following code uses the ASPxClientReportDesigner.GetJsonReportModel method to serialize the report loaded in the Report Designer and sends the JSON string to the controller. The controller deserializes the report with the IReportJsonSerializer.DeserializeFromJson(String) method and calls the XtraReport.SaveLayoutToXml(Stream) method to save the report in XML format.

cshtml
<script type="text/javascript">
    function OnSaveButtonClick() {
        var reportTab = reportDesigner1.GetCurrentTab();
        var reportLayout = reportDesigner1.GetJsonReportModel();
        var reportUrl = reportTab.url();
        $.post("/Home/SetReport", { layout: JSON.stringify({ "XtraReportsLayoutSerializer": reportLayout }), url: reportUrl });
    }
</script>
<button onclick="OnSaveButtonClick()">Click To Save</button>

@{
    var designer = Html.DevExpress().ReportDesigner("reportDesigner1")
        .Height("1000px")
        .Bind("TestReport")
}
@designer
cs
public IActionResult SetReport([FromServices] IReportJsonSerializer reportJsonSerializer, [FromForm] string layout, [FromForm] string reportName)
        {
            var report = reportJsonSerializer.DeserializeFromJson(layout);
            using (var stream = new System.IO.MemoryStream())
            {
                report.SaveLayoutToXml(stream);
                //...
            }
            return Ok();
        }

See Also

IReportJsonSerializer Members

DevExpress.XtraReports.Web.ReportDesigner.Services Namespace