我jsonData
用来绑定到 ajqgrid
但我也想model.total amount
在字段中使用。
那么我怎样才能返回它以在其中jsonData
使用它<td>
呢?
看法
<table>
<tr>
<td>@Model.TotalAmount</td>
</tr>
</table>
控制器
public ActionResult GetDocPendingDetails(string strPA, string strEmpCode, string StrModeOfPayment) // Sends PA to bind the gridview
{
string StrEmpcode = ""; // to be changed
cmn_top objCmn_top = new cmn_top();
DataTable dtData = new DataTable();
Items objitem = new Items();
if (StrModeOfPayment == "All")
{
StrModeOfPayment = "";
}
dtData = objCmn_top.Reports_GetData__DocPendingPayment(strPA, StrEmpcode, StrModeOfPayment);
ViewBag.TotalAmount = dtData.AsEnumerable().Sum(x => x.Field<double>("fl_approvedamt")).ToString(); // to be changed later
int totalRecords = dtData.Rows.Count;
var jsonData = new
{
totalamount = ViewBag.TotalAmount,
total = totalRecords,
rows =
(
from dtRow in dtData.AsEnumerable()
select new
{
cell = new string[]
{
dtRow.Field<string>("ch_docno"),dtRow.Field<string>("ch_empcode"),dtRow.Field<string>("ch_sapvoucherno"), dtRow.Field<string>("CH_PSA_CODE"),dtRow.Field<double>("fl_approvedamt").ToString()
}
}
)
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
这是我的 jqgrid
$("#list").GridUnload();
$("#list").jqGrid({
url: '/Reports/GetDocPendingDetails',
datatype: 'json',
mtype: 'GET',
colNames: ['Document No.', 'Document Owner', 'SAP Document No', 'PSA', 'Approved Amount'],
colModel: [
{ name: 'ch_docno', index: 'ch_docno', width: 100, align: 'center' },
{ name: 'ch_empcode', index: 'ch_empcode', width: 250, align: 'left' },
{ name: 'ch_sapvoucherno', index: 'ch_sapvoucherno', width: 100, align: 'center' },
{ name: 'CH_PSA_CODE', index: 'CH_PSA_CODE', width: 200, align: 'left' },
{ name: 'fl_approvedamt', index: 'fl_approvedamt', width: 100, align: 'center' }
],
emptyrecords: "Empty records",
height: 'auto',
loadtext: 'Loading.....',
sortorder: 'asc',
caption: " Documents Pending For Payment ",
shrinkToFit: true,
rownumbers: true,
rowNum: -1,
postData: { strPA: selectedPA, StrModeOfPayment: modeOfPayment },
viewrecords: true,
gridComplete: function () {
var recs = parseInt($("#list").getGridParam("records"));
if (isNaN(recs) || recs == 0) {
$("#gridWrapper").hide();
$("#DivEmptyRecords").show();
}
else {
$('#gridWrapper').show();
$("#DivEmptyRecords").hide();
}
}
});
//document.getElementById("tdTotalAmount").innerHTML = jsonData.TotalAmount;
}