Reputation: 113
I read this article about jtable with mvc at codeproject.com/script/Articles/ArticleVersion.aspx?aid=277576&av=419297
I try it. But when run , i get error An error occured while communicating to the server.
Please see my code . In controller
[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 });
}
}
And in View
$('#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');
In here , all file script and stylesheet is ok. When i see log in chrome , i found
Request URL:http://localhost:27508/HomeController/LocalList?jtStartIndex=0&jtPageSize=10&jtSorting=LOCATION_ID%20ASC
Request Method:POST
Status Code:404 Not Found
Can you tell me what mistake or wrong occurs in here ? and how to fix it. Thank guys.
Upvotes: 4
Views: 492
Reputation: 113
I founded as follow
1) Remove [HttpPost]
2) Edit listAction listAction: 'Home/LocalList'
It's work fine.
Upvotes: 0
Reputation: 11
It looks like the listAction is pointing to a non existing url (due to the HTTP-error 404).
Are you able to manually download the json using the request url you found in the log?
Upvotes: 1