[HttpPost]
public JsonResult StudentList(int id= 0, int id2= 0)
{
try
{
//Get data from database
List<Student> students = _repository.StudentRepository.GetStudents(id,id2);
//Return result to jTable
return Json(new { Result = "OK", Records = students},JsonRequestBehaviour.AllowGet);
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message },JsonRequestBehaviour.AllowGet);
}
}
My jquery
$("#DDL_id").change(function(){
//fill dropdown2 "DDL_idd" by ajax via get json call
});
$("#DDL_idd").change(function(){
var id= $("#DDL_id").val();
var idd= $("#DDL_idd").val();
var url = '/admin/StudentList?id1=' +id + '&id2='+idd;
$('#General_InfoTableContainer').jtable({
title: 'General_Info List',
actions: {
listAction: url
},
fields: {
RID: {
key: true,
create: false,
edit: false,
list: true,
title: 'RID',
width: '5%'
},
Quote: {
title: 'Open Quote',
list: true,
width: '15%',
},
Customer_Name: {
list: true,
title: 'Customer',
width: '25%'
}
}
});
//Load student list from server
$('#General_InfoTableContainer').jtable('load');
});
});
For first time I am getting correct id of both dropdowns in my controller but after that if I change my selection from dropdown, my action did not getting new value and it executing with old value always "StudentList(int id1= 0, int id2= 0)" id1 and id2 have old value and never reset again I have done with
$.ajaxSetup({ cache: false });
and
[Nocache]
on controller action and other solutions. Please Help.
Your problem is one variable scope / closures.
When the jTable options object is create and passed to the jTable constructor, whatever value was in url is fixed as the listAction.
It looks like you are trying to perform a "filter" operation
Just set the listAction to the static part of the url
listAction: '/admin/StudentList',
then when you populate the table
$('#General_InfoTableContainer').jtable('load',{
'id1':$("#DDL_id").val(),
'id2':$("#DDL_idd").val()});