Back to Devexpress

Lesson 2 - Use the Resulting Query

aspnet-120100-aspnet-mvc-extensions-query-builder-getting-started-lesson-2-use-the-resulting-query.md

latest2.4 KB
Original Source

Lesson 2 - Use the Resulting Query

  • Oct 30, 2020
  • 3 minutes to read

This lesson demonstrates how to use queries that the Query Builder generates to supply data to the DevExpress ASP.NET MVC GridView control.

Tip

For a complete sample project, see the following DevExpress Support Center example: http://www.devexpress.com/example=T624853.

Pass the Query Data to the GridView

  1. Create a new Partial View file (for instance, GridViewPartial.cshtml ), since the GridView updating mechanism requires declaring its extension in the Partial View. Use the ExtensionsFactory.GridView helper method and pass the GridViewSettings object as a parameter to configure the extension as shown below:

  2. Move the Query Builder extension’s declaration from the Index.cshtml file to a new separate View file ( QueryBuilder.cshtml in this example).

  3. In the Index.cshtml file, render the GridView and provide the capability to run the Query Builder using the following code:

  4. In the Query Builder controller, modify the Save action to save the QueryBuilderSaveCallbackResult.SelectStatement property value to the session variable and redirect a browser to the page with the GridView.

  5. Open the HomeController file and implement the action methods as demonstrated below:

View the Result

Run the application to see the GridView displaying the default data and click the Run Query Builder link.

In the invoked Query Builder, construct a query and click the Save toolbar button.

This opens the page with the GridView that shows the obtained data.