Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ASP MVC和Datatables:通过ajax获取数据时出错_Javascript_Jquery_Asp.net Mvc_Datatables - Fatal编程技术网

Javascript ASP MVC和Datatables:通过ajax获取数据时出错

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>

我试图通过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>
         <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);
    }