❔ Using DataTable in .cshtml File with JavaScript

Hello everyone,

I'm still new to using C#, and I'm trying to figure out how you display data from a SQL database that is called in the OnGet() method of my page with a paginated table.

using System.Data;
using System.Data.SqlClient;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ExampleWebsite.Pages;

public class Responses : PageModel
{
    public void OnGet()
    {
        DataTable table = new DataTable();
        const string connectionString = "secret";
        using (SqlConnection connection = new SqlConnection(
                   connectionString )
               )
        using(SqlCommand cmd = new SqlCommand(
                  "SELECT * FROM Responses", 
                  connection )
              )
        using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
        {
            adapter.Fill(Dt);
        }
    }
}


This is where I am so far. Any help is greatly appreciated.
Was this page helpful?