我正在尝试在Jquery中使用数据表,所以我有一个带有此代码的Controller:
namespace wb01.Controllers
{
public class ConsommationsController : Controller
{
private database db = new database();
// GET: Consommations
public ActionResult Index()
{
var consommation = db.Consommation.Include(c => c.Unités_de_prod);
return View();
}
public ActionResult GetList()
{
using (database db = new database())
{
var listconsom = db.Consommation.ToList<Consommation>();
return Json(new { data = listconsom }, JsonRequestBehavior.AllowGet);
}
}
在我的视图中我有这个代码: 在我的视图中我有这个代码: 在我的视图中我有这个代码: 在我的视图中我有这个代码:
@model IEnumerable<wb01.Models.Consommation>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables_themeroller.css">
<br />
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table @*class="display"*@ id="tableconsommation">
<thead>
<tr>
<th>Date_consommation</th>
<th>Qtité_consommée</th>
<th>Id_unité</th>
<th>Unités_de_prod</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Date_consommation</th>
<th>Qtité_consommée</th>
<th>Id_unité</th>
<th>Unités_de_prod</th>
</tr>
</tfoot>
</table>
@section scripts {
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$("#tableconsommation").dataTable({
"ajax": {
"url": "/Consommations/GetList",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "Date_consommation", "data": "Date_consommation" },
{ "data": "Qtité_consommée", "data": "Qtité_consommée" },
{ "data": "Id_unité", "data": "Id_unité" },
{ "data": "Unités_de_prod", "data": "Unités_de_prod" },
],
"serverSide": "true",
"order": [0, "asc"],
"processing": "true",
});
});
</script>
}