控制器里的代码如下:
private MySqlDbHelper msh = new MySqlDbHelper();
public ActionResult Index()
{
string sql = "select * from deviceType";
DataTable dt = msh.GetDataTable(sql, null);
return View(dt);
}
视图里用DataTable代码如下:
@model System.Data.DataTable
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<table>
@foreach (System.Data.DataRow dr in Model.Rows)
{
<tr>
<td>
@dr["deviceId"]
</td>
<td>
@dr["dName"]
</td>
<td>
@dr["cTime"]
</td>
</tr>
}
</table>