jquery数据表json数据没有绑定? mvc4

时间:2014-03-28 07:31:36

标签: jquery json asp.net-mvc-4

我试过这样但有些事情是错的,我无法继续前进。

我的观看代码:

<html>    
    <head>   
   <script src="@Url.Content("~/Scripts/jquery-2.1.0.js")"  type="text/javascript"> </script>
  <script src="@Url.Content("~/Scripts/jquery.dataTables.js")" type="text/javascript"></script>
 <script src="@Url.Content("~/Scripts/index.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/demo_page.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/demo_table.css")" rel="stylesheet" type="text/css" />

        <script type="text/javascript">
            $(document).ready(function () {
                debugger;
                alert("dfdfd");
                $('#myDataTable').dataTable( {
                    "bServerSide": true,
                    "sAjaxSource": "Home/AjaxHandler",
                    "bProcessing": true,
                    "aoColumns": [
                                    {
                                        "sName": "ID",
                                        "bSearchable": false,
                                        "bSortable": false,
                                        "fnRender": function (oObj) {
                                            return '<a href=\"Details/' +
                                            oObj.aData[0] + '\">View</a>';
                                            alert(oObj);
                                        }
                                    },

                                    { "sName": "COMPANY_NAME" },
                                    { "sName": "ADDRESS" },
                                    { "sName": "TOWN" }
                    ]
                });
            });

</script>
    </head>
    <body>
                <table id="myDataTable" class="display">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Company name</th>
                            <th>Address</th>
                            <th>Town</th>
                        </tr>
                    </thead>
                    </table>
</body>

我的家庭控制器代码:

public class HomeController : Controller
{

   public ActionResult AjaxHandler(jQueryDataTableParamModel param)
   {
       return Json(new
       {
           sEcho = param.sEcho,
           iTotalRecords = 97,
           iTotalDisplayRecords = 3,
           aaData = new List<string[]>() {
                new string[] {"1", "Microsoft", "Redmond", "USA"},
                new string[] {"2", "Google", "Mountain View", "USA"},
                new string[] {"3", "Gowi", "Pancevo", "Serbia"}
                }
        },
        JsonRequestBehavior.AllowGet);
    }
}

直到"aoColumns" : { "sName" : "ID"}代码工作正常我创建了一些警报,直到它发生了。

来自Json的数据完全没有约束力 JSON OUTPUT:

{
   "sEcho":null,
   "iTotalRecords":97, 
   "iTotalDisplayRecords":3,
   "aaData":[
              ["1","Microsoft","Redmond","USA"],
              ["2","Google","Mountain View","USA"],                    
              ["3","Gowi","Pancevo","Serbia"]
            ]
}

更新 我的错误:还编辑了上面的查看部分检查

'iexplore.exe' (Script): Loaded 'Script Code (Windows Internet Explorer)'. 
Unhandled exception at line 3398, column 4 in http://localhost:49205/Scripts/jquery-2.1.0.js
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support this property or method
Unhandled exception at line 39, column 7 in http://localhost:49205/Scripts/jquery.dataTables.js
0x800a1391 - Microsoft JScript runtime error: 'jQuery' is undefined
Unhandled exception at line 2, column 1 in http://localhost:49205/Scripts/index.js
0x800a138f - Microsoft JScript runtime error: Object expected

REGARDS

1 个答案:

答案 0 :(得分:0)

终于得到了解决方案,我并不完全满意。我在使用它时使用j-query 2.1我得到J-query未定义的异常。 但是现在我尝试使用j-query 1.4它现在工作正常:)

感谢您对Ty的看法