如何使用ASP.NET MVC服务器端数据填充jquery数据 [英] How to populate jquery datable with ASP.NET MVC server side data

查看:56
本文介绍了如何使用ASP.NET MVC服务器端数据填充jquery数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器动作,其参数返回json数据以提供jQuery数据表。到目前为止,我得到一个空表和ajax错误:...有关此错误的更多信息,请参阅http://datatables.net/tn/7,并在表中显示正在加载...消息。任何帮助都非常感谢。



I have a controller action with parameters that returns json data to feed jQuery datatable. So far I'm getting an empty table and ajax error: "...For more information about this error, please see http://datatables.net/tn/7" with the message "Loading..." in the table. Any help is highly appreciated.

public ActionResult GetItems(String description, string linenumber)
{
  ---retracted
   return Json(new { data = itemList }, JsonRequestBehavior.AllowGet);
}




Line Number: <input type="text" id="myInput1"><br>
Description: <input type="text" id="myInput2"><br>




<table class="table" id="ItemsTable">
<thead>
<tr>
<th>ID</th>
<th>Quantity</th>
</tr>
</thead>
</table>





我的尝试:





What I have tried:

$(document).ready(function () {
var lnbr = $("#myInput1").val();
var desc = $("#myInput2").val()
var oTable = $('#ItemsTable').dataTable({
"ajax" : {
"url" : "/Home/GetItems",
"type" : "get",
"datatype" : "json",
"data" : { description:desc, linenumber: lnbr}
},
"columns": [(
{"data" : "ID", "autowidth" : true },
{"data" : "Qty", "autowidth" : true },
)]
});
});

推荐答案

(文档) .ready(function(){
var lnbr =
(document).ready(function () { var lnbr =


(#myInput1)。val();
var desc =
("#myInput1").val(); var desc =


(#myInput2)。val()
var oTable =
("#myInput2").val() var oTable =


这篇关于如何使用ASP.NET MVC服务器端数据填充jquery数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆