【发布时间】:2018-01-23 10:13:08
【问题描述】:
我正在使用 ajax 数据表加载数据,但我想在每一行中进行一些按钮编辑和详细信息。我试过但失败了。您的帮助将不胜感激。
这是我在 Ajax 数据表中使用表格和数据加载的 cshtml 标记:
<div class="row">
<div class="col-md-12 col-sm-12 col-lg-12">
<table id="myTable">
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Joing Date</th>
</tr>
</thead>
</table>
</div>
</div>
<script>
$(document).ready(function() {
$('#myTable').DataTable({
"ajax": {
"url": "/Employee/loaddata",
"type": "GET",
"datatype": "json"
},
"responsive": true,
"columns": [{
"data": "FirstName",
"autoWidth": true
},
{
"data": "LastName",
"autoWidth": true
},
{
"data": "JoiningDate",
"autoWidth": true
}
]
});
});
</script>
这是控制器代码:
public class EmployeeController : Controller
{
private EmployeeContext db = new EmployeeContext();
public ActionResult loaddata()
{
db.Configuration.LazyLoadingEnabled = false;
var clientes = db.Employees.OrderBy(a => a.FirstName).ToList();
return Json(new { data = clientes }, JsonRequestBehavior.AllowGet);
}
}
【问题讨论】:
标签: jquery ajax asp.net-mvc