All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

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.v20.2.dll

Declaration

public QueryBuilderClientSideEventsBuilder SaveQueryRequested(
    string callback
)
Public Function SaveQueryRequested(
    callback As String
) As QueryBuilderClientSideEventsBuilder

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