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.
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