Skip to main content
All docs
V24.2

QueryBuilderClientSideEventsBuilder.SaveQueryRequested(String) Method

Specifies the JavaScript function that handles the Web Query Builder‘s SaveQueryRequested client-side event.

Namespace: DevExpress.AspNetCore.Reporting.QueryBuilder

Assembly: DevExpress.AspNetCore.Reporting.v24.2.dll

NuGet Package: DevExpress.AspNetCore.Reporting

Declaration

public QueryBuilderClientSideEventsBuilder SaveQueryRequested(
    string callback
)

Parameters

Name Type Description
callback String

The name of a JavaScript function used to handle the SaveQueryRequested event.

Returns

Type Description
QueryBuilderClientSideEventsBuilder

A reference to the QueryBuilderClientSideEventsBuilder instance after the event handler is specified.

Remarks

The SaveQueryRequested event allows you to get the query object, constructed in the Web Query Builder. This event is raised when the user clicks Save in the Web Query Builder toolbar.

Use the GetSaveQueryModel method of the client-side Query Builder object to obtain the query model. The following code gets the query model and sends it to the server:

@model DevExpress.XtraReports.Web.QueryBuilder.QueryBuilderModel

<link href="~/css/querybuilder.part.bundle.css" rel="stylesheet" />
<script src="~/js/querybuilder.part.bundle.js"></script>

<script>
    function SaveQueryRequested() {
        var saveQueryModel = webQueryBuilder.GetSaveQueryModel();
        $.ajax({
            url: "/Home/SaveQuery",
            type: "POST",
            data: saveQueryModel,
            success: function(result) {
                window.location = "/";
            }
        });
    }
</script>
@(Html.DevExpress()
    .QueryBuilder("webQueryBuilder")
    .ClientSideEvents( x => {
        x.SaveQueryRequested("SaveQueryRequested");
    })
    .Height("400px")
    .Bind(Model))

On the server side, use the IQueryBuilderInputSerializer service to restore the QueryBuilderInput object and retrieve the query:

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using DevExpress.XtraReports.Web.QueryBuilder.Services;
using System.ComponentModel.DataAnnotations;
using DevExpress.DataAccess.Web.QueryBuilder;
using DevExpress.DataAccess.Sql;
// ...
  public async Task<IActionResult> SaveQuery(
  [FromServices] IQueryBuilderInputSerializer queryBuilderInputSerializer,
  [FromForm] DevExpress.DataAccess.Web.QueryBuilder.DataContracts.SaveQueryRequest saveQueryRequest)
  {
      try
      {
          var queryBuilderInput = queryBuilderInputSerializer.DeserializeSaveQueryRequest(saveQueryRequest);
          // Get the query constructed in the Query Builder.
          SelectQuery resultingQuery = queryBuilderInput.ResultQuery;
          string sql = queryBuilderInput.SelectStatement;
          return new RedirectToActionResult("Index", "Home", null);
      }
      catch (Exception ex)
      {
          var validationException = ex.InnerException as DevExpress.DataAccess.Sql.ValidationException;
          return Problem(validationException?.Message ?? ex.Message);
      }
  }
See Also