I am having difficulty getting my DataRow results to display in a table on a partial view. Basically what I am trying to do is pass the results of a SQL query to a partial view and display the results in a table. Note the results will vary every time so I cannot hard code any of the column names, they must be dynamically created by my code.

This is my controller action, its purpose is to run a sql query and pass the results to the partial view in question. Please note the connection string has been removed from the code as it contains username and password but it is present and working on my code, also note that I have debugged this and the list I am returning has the data I expected it to have.

```
List<DataRow> list = null;

string connString = "Connection String Goes Here";
using (SqlConnection conn = new SqlConnection(connString))
{
    using (SqlCommand objCommand = new SqlCommand(custSQL, conn))
    {
        objCommand.CommandType = CommandType.Text;
        DataTable dt = new DataTable();
        SqlDataAdapter adp = new SqlDataAdapter(objCommand);
        conn.Open();
        adp.Fill(dt);

        if (dt != null)
        {
            list = dt.AsEnumerable().ToList();
        }
    }
}

return PartialView("_CustomSQL", list);

```

This is the view, Note I am getting red line errors under DataRow and DataColumn I only wrote this code to better illustrate what I am trying to achieve which is to display the results of my SQL query in a html style table:

```
@model System.Collections.Generic.List<System.Data.DataRow>

<table>
    <thead>
        <tr>
            @foreach (DataColumn col in Model.Columns)
            {
                <th>@col.ColumnName</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (DataRow row in Model.Rows)
        {
            <tr>
                @foreach (DataColumn col in Model.Columns)
                {
                    <td>@row[col.ColumnName]</td>
                }
            </tr>
        }
    </tbody>
</table>

```