MVC how do you pass parameter values?
MVC how do you pass parameter values?
I have 2 filter text boxes:
How do I pass these values to my controller below? How do I access them from controller "GetAgencies()"?
client code:
[code]
$(document).ready(function () {
$('#agencyList').dataTable({
"bServerSide": true,
"sAjaxSource": "GetAgencies",
"bProcessing": true,
"iDisplayLength": 10,
"bLengthChange": false,
"bFilter": false,
"aoColumns": [
{ "sName": "Agency_Ori",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '' + oObj.aData[0] +'';
}
},
{ "sName": "Agency_Name" },
{ "sName": "COPSAuditNumber" },
{ "sName": "OIGAuditNumber" }
]
});
});
[/code]
My controller:
[code]
public ActionResult GetAgencies(jQueryDataTableParamModel param)
{
AuditDAL ad = new AuditDAL();
var agencies = ad.SearchAgencies("Ak001", "");
string col = param.sColumns.Split(',')[param.iSortCol_0];
string orderby = col + " " + param.sSortDir_0;
IEnumerable filteredAgencies = agencies;
var results = filteredAgencies
.Skip(param.iDisplayStart)
.Take(param.iDisplayLength);
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = agencies.Count(),
iTotalDisplayRecords = filteredAgencies.Count(),
aaData = (
from n in results
select new[]
{
n.Agency_Ori,
n.Agency_Name,
n.COPSAuditNumber,
n.OIGAuditNumber
}).ToArray()
},
JsonRequestBehavior.AllowGet);
}
[/code]
How do I pass these values to my controller below? How do I access them from controller "GetAgencies()"?
client code:
[code]
$(document).ready(function () {
$('#agencyList').dataTable({
"bServerSide": true,
"sAjaxSource": "GetAgencies",
"bProcessing": true,
"iDisplayLength": 10,
"bLengthChange": false,
"bFilter": false,
"aoColumns": [
{ "sName": "Agency_Ori",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '' + oObj.aData[0] +'';
}
},
{ "sName": "Agency_Name" },
{ "sName": "COPSAuditNumber" },
{ "sName": "OIGAuditNumber" }
]
});
});
[/code]
My controller:
[code]
public ActionResult GetAgencies(jQueryDataTableParamModel param)
{
AuditDAL ad = new AuditDAL();
var agencies = ad.SearchAgencies("Ak001", "");
string col = param.sColumns.Split(',')[param.iSortCol_0];
string orderby = col + " " + param.sSortDir_0;
IEnumerable filteredAgencies = agencies;
var results = filteredAgencies
.Skip(param.iDisplayStart)
.Take(param.iDisplayLength);
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = agencies.Count(),
iTotalDisplayRecords = filteredAgencies.Count(),
aaData = (
from n in results
select new[]
{
n.Agency_Ori,
n.Agency_Name,
n.COPSAuditNumber,
n.OIGAuditNumber
}).ToArray()
},
JsonRequestBehavior.AllowGet);
}
[/code]
This discussion has been closed.
Replies
[code]aaData[/code][/quote]
Your aaData parameter appears to be malformed. This should be a json encoded key name, not an href tag.
Allan