控制器里的代碼如下: private MySqlDbHelper msh = new MySqlDbHelper(); public ActionResult Index() { string sql = "select * from deviceType"; DataTable dt = msh. ...
控制器里的代碼如下:
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>