gpt4 book ai didi

Jquery 数据表显示消息未找到匹配的记录

转载 作者:行者123 更新时间:2023-12-01 05:35:16 25 4
gpt4 key购买 nike

我想将收到的json数据绑定(bind)到jquery数据表。我有以下问题。1. 我的HTML代码正确吗?2. 接收到的Json数据格式正确吗?3.我是否使用正确的脚本来渲染jquery数据表,请帮忙。

我附上了代码以及收到的数据的屏幕截图。

public JsonResult This_is_final(int FirstNameCount, int LastNameCount, int TotalSalary, int GenderCount)
{
List<Counting> l = new List<Counting>();
l.Add(new Counting() { FirstNamecount = FirstNameCount, LastNamecount = LastNameCount, Salary = TotalSalary, Gendercount = GenderCount });
//System.Web.Script.Serialization.JavaScriptSerializer jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer();

//string aaData = jSearializer.Serialize(l);
//Console.WriteLine(FirstNameCount + "" + LastNameCount + "" + TotalSalary + "" + GenderCount);
// aaData = "{\"data\": " + aaData + "}";
var todoListsResults = l.Select(
a => new
{

a.FirstNamecount,
a.LastNamecount,
a.Salary,
a.Gendercount

});

var jsonData = new
{
iTotalRecords= "54",
iTotalDisplayRecords="22",
aadata = todoListsResults
};
return Json(jsonData, JsonRequestBehavior.AllowGet);


}


Jquery script:-
<小时/>
function callme(fncount, lncount, i, gndr) { 


$('#example').dataTable({
"ajax": {
url: "/TodoList/This_is_final",
type: "POST",
data: {
'FirstNameCount': fncount, 'LastNameCount': lncount, 'TotalSalary': i, 'GenderCount': gndr
},
dataSrc: function (json) {

alert(JSON.stringify(json));
return { "data":json };
}
},
"processing": true,
"serverSide": true,
"ordering": false,
"searching": true,
"columns": [
{ "mdata": "FirstNamecount" },
{ "mdata": "LastNamecount" },
{ "mdata": "TotalSalary" },
{ "mdata": "GenderCount" }
]
});

}

Image

最佳答案

我还使用数据表进行数据绑定(bind),但我使用 JQuery post 函数来获取 JsonResult 数据

$.post("../TodoList/This_is_final", { "FirstNameCount": fncount, "LastNameCount": lncount},
function (data) { if (data != null) {
var table = $("#example").dataTable({
"iDisplayLength": 10,
"aaData": data,
"aoColumns": [
{ "sTitle": "First Name", "sWidth": "20%"},
{ "sTitle": "Last Name", "sWidth": "20%"}]
})} }

在 View

public JsonResult This_is_final(int FirstNameCount, int LastNameCount)
{
List<Counting> l = new List<Counting>();
l.Add(new Counting() { FirstNamecount = FirstNameCount, LastNamecount = LastNameCount });
var todoListsResults = l.Select(
a => new[]
{

a.FirstNamecount,
a.LastNamecount,
}).ToArray();

return Json(todoListsResults, JsonRequestBehavior.AllowGet);
}

更新了您的代码..

关于Jquery 数据表显示消息未找到匹配的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34508212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com