控制器
public ActionResult GetUsers()
{
//创建上下文对象
BackgroundDataContext data = new BackgroundDataContext();
string result = string.Empty;
//定义查询语句,查询出TS_Role表中的数据
var count = from index in data.TS_User
select new {index.UserID, index.LoginName, index.LoginPwd,index.JoinTime, index.Status, index.Remark };
return Json(count);
}
视图
<script type="text/x-jquery-tmpl" id="counts">
<tr>
<td height="18" bgcolor="#FFFFFF">
<div align="center" class="STYLE1">
<input name="checkbox" type="checkbox" class="STYLE2" value="checkbox" />
</div>
</td>
<td height="18" bgcolor="#FFFFFF" class="STYLE2"><div align="center" class="STYLE2 STYLE1">${UserID}</div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1">${LoginName}</div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1">${Status}</div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1">${result}</div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center"><a href="#">${Remark}</a></div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center"><img src="/images/037.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="#" myid="${UserID}">编辑</a><span class="STYLE1">]</span></div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center"><span class="STYLE2"><img src="/images/010.gif" width="9" height="9" /> </span><span class="STYLE1">[</span><a href="#" myid="${UserID}">删除</a><span class="STYLE1">]</span></div></td>
</tr>
</script>
<script>
jQuery(function () {
$.post("@Url.Action("GetUsers")", "", function (data) {
console.log(data);
//通过模板完成数据填充后,追加到tbody中
$("#count").append($("#counts").tmpl(data));
}, "json")
)}