从 MVC 加载数据 Jtable 时出错?
Error load data Jtable from MVC?
我在 codeproject.com/script/Articles/ArticleVersion.aspx?aid=277576&av=419297
阅读了这篇关于 jtable with mvc 的文章
我试试。但是当 运行 时,我得到错误 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');
在这里,所有文件脚本和样式表都可以。当我看到登录 chrome 时,我发现
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 listAction: 'Home/LocalList'
工作正常。
我在 codeproject.com/script/Articles/ArticleVersion.aspx?aid=277576&av=419297
阅读了这篇关于 jtable with mvc 的文章我试试。但是当 运行 时,我得到错误 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');
在这里,所有文件脚本和样式表都可以。当我看到登录 chrome 时,我发现
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 listAction: 'Home/LocalList'
工作正常。