Javascript ASP MVC和Datatables:通过ajax获取数据时出错
我试图通过ajax将datatables 1.10.9中的数据加载到ASP MVC控制器 我有下表:Javascript ASP MVC和Datatables:通过ajax获取数据时出错,javascript,jquery,asp.net-mvc,datatables,Javascript,Jquery,Asp.net Mvc,Datatables,我试图通过ajax将datatables 1.10.9中的数据加载到ASP MVC控制器 我有下表: <table id="Demo" class="table table-striped" cellspacing="0"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.Code) </th>
<table id="Demo" class="table table-striped" cellspacing="0">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Code)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
当chrome inspector中的ajax请求调用此控制器时,我看到以下答案:
[
{"vehicle":[],"Id":1,"Code":"Car1","Description":"Car1 Description"},
{"vehicle":[],"Id":2,"Code":"Car2","Description":"Car2 Description"}
]
为什么在数据表中我看不到任何行?我只看到加载。。。。
在chrome inspector的控制台中,我只看到以下错误:
Uncaught TypeError: Cannot read property 'length' of undefined
在jquery.dataTables.min.js中
更新
已解决将asp mvc控制器更改为:
public JsonResult GetVehicle()
{
return Json(new { data = db.vehicletype.ToList() }, JsonRequestBehavior.AllowGet);
}
试试ajax:{url:'GetVehicle',dataSrc:},因为dataSrc是ajax选项的一个子选项。@Gyrocode.com是正确的->
Uncaught TypeError: Cannot read property 'length' of undefined
public JsonResult GetVehicle()
{
return Json(new { data = db.vehicletype.ToList() }, JsonRequestBehavior.AllowGet);
}