编程爱好者联盟 2016-10-20
一:参数传递及接收
JavaScript:
黄背景部分为参数传递关键
<script type="text/javascript"> var table; var delId; $(document) .ready(function () { table = $('#tableQuetions') .dataTable({ //"dom": '<"H"fr > t <"F"lip >', "pagingType": "full_numbers", "processing": true, "serverSide": true, "scrollX": true, "ordering ": false, "scrollY": "350px", "searching": false, "ajax": { "url": "/RFTraining/Exam/ExamQuetionList", "type": "POST", "data": function (d) { d.questionName = $("#QuestionNameForSearch").val(); d.questionType = $("#QuestionTypeForSearch").val(); } }, "columnDefs": [ { "render": function (data, type, row) { return '<input type="button" value="删除" class="btn btn-link" onclick="onDel(' + row["ID"] + ')" />'; //+'<input type="button" value="编辑" class="btn btn-link" onclick="onEdit(' + //row["ID"] + //')" />'; }, "targets": 6 } ], columns: [ { data: 'ROWNO' }, { data: 'ID' }, { data: 'QUESTIONTYPE' }, { data: 'QUESTIONNAME' }, { data: 'QUESTIONSCORE' }, { data: 'CREATETIME' }, { data: 'edit' } ], "lengthMenu": [ [20, 50, 100, 200], [20, 50, 100, 200] ], //每页显示条数设置 "Info": true, "oLanguage": { //国际语言转化 "oAria": { "sSortAscending": " - click/return to sort ascending", "sSortDescending": " - click/return to sort descending" }, "sLengthMenu": "显示 _MENU_ 记录", "sZeroRecords": "对不起,查询不到任何相关数据", "sEmptyTable": "未有相关数据", "sLoadingRecords": "玩命加载中...", "sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录。", "sInfoEmpty": "当前显示0到0条,共0条记录", "sInfoFiltered": "(数据库中共为 _MAX_ 条记录)", "sProcessing": "玩命加载中...", "sSearch": "模糊查询:", "sUrl": "", //多语言配置文件,可将oLanguage的设置放在一个txt文件中,例:Javascript/datatable/dtCH.txt "oPaginate": { "sFirst": "首页", "sPrevious": " 上一页 ", "sNext": " 下一页 ", "sLast": " 尾页 " } } }); }); } </script>
C#:
参数获取
rfExamQuetion.QuestionName = Request.Params["questionName"]; rfExamQuetion.QuestionType = int.Parse(Request.Params["questionName"]);
二:自定义提交
table.ajax.reload();//官方写的是这个,不知道为啥我用的时候报错TypeError: cannot read property 'reload' of undefined 'ajax' table.api().ajax.reload();//上面报错的可以用这个方法