我在codeproject.com/script/Articles/ArticleVersion.aspx上读到了这篇关于jtable with mvc的文章?aid=277576&av=419297
我试过了。但当运行时,我得到错误An error occured while communicating to the server.
请查看我的代码。控制器内
[HttpPost]
public JsonResult LocalList(int jtStartIndex, int jtPageSize, string jtSorting)
{
try
{
string localCount = db.Database.SqlQuery<string>("Select Count(*) FROM Location").ToString();
IEnumerable<LOCATION> query = db.LOCATIONs;
if (jtSorting.Equals("LOCATION_ID ASC"))
{
query = db.LOCATIONs.OrderBy(e => e.LOCATION_ID).Skip(jtStartIndex).Take(jtPageSize).ToList();
}
else
{
query = db.LOCATIONs.OrderBy(e => e.LOCATION_ID).Skip(jtStartIndex).Take(jtPageSize).ToList();
}
return Json(new { Result = "OK", Records = query, TotalRecordCount = int.Parse(localCount) });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
在视图中
$('#div_local').jtable({
title: 'List Location',
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
sorting: true, //Enable sorting
defaultSorting: 'LOCATION_ID ASC', //Set default sorting
actions: {
listAction: 'HomeController/LocalList'
},
fields: {
AREA_ID: {
key: false,
list: false,
create: false
},
LOCATION_ID: {
key: true,
list: false,
create: false
},
LOCATION_NAME: {
title: 'Name'
},
LOCATION_DES: {
title: 'Des'
}
}
});
$('#div_local').jtable('load');
在这里,所有的文件脚本和样式表都可以
Request URL:http://localhost:27508/HomeController/LocalList?jtStartIndex=0&jtPageSize=10&jtSorting=LOCATION_ID%20ASC
Request Method:POST
Status Code:404 Not Found
你能告诉我这里发生了什么错误吗?以及如何修复。谢谢大家。
看起来listAction指向了一个不存在的url(由于HTTP错误404)。
你能使用你在日志中找到的请求url手动下载json吗?
我创建了如下
1) 删除[HttpPost]
2) 编辑列表操作listAction: 'Home/LocalList'
工作不错。