How to create dynamic report depend on user input by ASP.NET Core?

Arwa Sami 20 Reputation points
2023-02-26T09:52:23.6+00:00

I want to build a dynamic report by Asp.net core -EF-, I searched for many ways and ideas, but it doesn't support my idea, I am so disappointed, the core idea of my project is to get tables and columns names from the database and displays them for the user to choose which will it display in the report, and at last generate a dynamic report. how can I build this report in Asp.net core, Can anyone give me guidelines to start building my project? Thank you for your attention. I am waiting for your guide

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,178 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,263 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,016 Reputation points Microsoft Vendor
    2023-02-27T06:27:01.24+00:00

    Hi @Arwa Sami

    From your description, it seems that you want to show/hide columns dynamically, right? If that is the case, you can try to use the following methods:

    Method 1: Use EF core to execute the dynamically generated SQL commands.

    a. Use the following code to get the table columns: For example: get the Movie's columns:

              var entityType = _context.Model.FindEntityType(typeof(Movie));
                var properties = entityType.GetProperties();
                var schema = entityType.GetSchema();
                var tableName = entityType.GetTableName();
                var storeObjectIdentifier = StoreObjectIdentifier.Table(tableName, schema);
                List<string> moviescolumns = properties.Select(x => x.GetColumnName(storeObjectIdentifier))
                    .ToList();
    

    b. Use ViewBag/ViewData to transfer the columns to the view page, and then use checkbox to display the column name.

    c. After checked the checkbox, click the submit button to submit the selected value to the Controller action method.

    d. In the Action method, based on the selected columns to build the SQL query statement. And then use Sql Query or Database.ExecuteSqlCommand method to execute the sql command.

    e. Transfer the query result to view page and display the result.

    Method 2: Use JQuery Data table plugin.

    Some JQuery Data table plugin provides the function to show/hide columns dynamically. Such as JQuery DataTables.

    image1


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion