I am receiving a DataTable object from the controller and using that to display a table in the view with the following code:
@model System.Data.DataTable
<table width="65%">
<tr>
<th>USERNAME</th>
<th>ROLE</th>
<th>ACTIVE</th>
<th></th>
<th></th>
</tr>
@foreach(DataRow row in Model.Rows)
{
<tr>
@foreach (DataColumn column in Model.Columns)
{
<td>@row[column]</td>
}
<td>@Html.ActionLink("Edit", "Edit", new { id = row[0] })</td>
<td>@Html.ActionLink("Delete", "Delete",new{id=row[0]})</td>
</tr>
}
</table>
I'd like to add pagination so that the user doesn't have to scroll down for a long period when the table becomes populated with a lot of data. This is for a basic learning exercise that I'm doing where I've hard-coded all of the database SQL calls in the relevant controller action methods. I'm not using an ORM like NHibernate so ideally I'm looking for a solution that just uses the DataTable object on the server side.
Here's the code from the controller (with the DB specifics removed):
public ActionResult Index()
{
string oradb = "Data Source = XXXXXXXXXXXXXXXXXXX";
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
string sql = " SELECT USER_ROLE_ID, USERNAME, ROLE, ACTIVE_IND FROM LD_USER_ROLE";
OracleDataAdapter adapter = new OracleDataAdapter(sql, conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
conn.Close();
return View(dt);
}