asp.net mvc - How to Pass Value from Control to View Json -
asp.net mvc - How to Pass Value from Control to View Json -
i beginner in asp.net mvc. here code, i'm looking expert help.
in code calculating saletotal
[httppost] public double saletotal(datetime? fromdate, datetime? todate) { var sales = s in db.salesmasters (s.billdate >= fromdate && s.billdate <= todate) select s.stotal; var salesreturn = s in db.sreturnmasters s.returndate >= fromdate && s.returndate <= todate select s.srtotal; double totalsales = sales.sum().getvalueordefault(); double totalsalesreturn = salesreturn.sum().getvalueordefault(); double balance = totalsales - totalsalesreturn; homecoming balance; } public actionresult allsalereport(jquerydatatableparammodel param, int? billno , datetime ? fromdate,datetime? todate) { double salestotal=saletotal(fromdate, todate); var sales = (from s in db.salesmasters (s.billdate >= fromdate && s.billdate <= todate ) select s).tolist(); var filteredsales=(from s in db.salesmasters (s.billdate >= fromdate && s.billdate <= todate && s.cancelflag==false ) select s).tolist(); var result = s in filteredsales.skip(param.idisplaystart).take(param.idisplaylength) select new[] { s.billdate.getvalueordefault().tostring("dd-mmm-yyyy"), convert.tostring(s.billno), s.refname, s.paymode, convert.tostring(s.netamt) }; homecoming json(new { secho = param.secho, itotalrecords = sales.count, itotaldisplayrecords = filteredsales.count, aadata = result, salesreturn = saletotal(fromdate, todate) }, jsonrequestbehavior.allowget); } my javascript load info datatable
function loadalldata() { var reporttable = $('#allsales').datatable({ "processing": true, //"bprocessing": true, "bjqueryui": false, "bserverside": true, "bfilter": false, //"bautowidth": true, "bdestroy": true, "idisplaylength": 20, //"sprocessing": "<img src=~/content/images/ajax-loader.gif />", "dom": 't<"clear">lfrtip', "sswfpath": "~/swf/copy_csv_xls_pdf.swf", "fnpredrawcallback": function () { $("#allsales").hide(); $("#loading").show(); // alert("pre draw"); }, "fndrawcallback": function () { $("#allsales").show(); $("#loading").hide(); // alert("draw"); }, "fninitcomplete": function () { }, "fnserverparams": function (aodata) { aodata.push({ "name": "fromdate", "value": $("#fromdate").val() }) aodata.push({ "name": "todate", "value": $("#todate").val() }) }, "sajaxsource": "/report/allsalereport", "footercallback": function (row, aodata, start, end, display) { var api = this.api(), aodata; // remove formatting integer info addition var intval = function (i) { homecoming typeof === 'string' ? i.replace(/[\$,]/g, '') * 1 : typeof === 'number' ? : 0; }; // total on pages info = api.column(4).data(); alert(data.length); // alert(salesreturn); total = data.length ? data.reduce(function (a, b) { homecoming intval(a) + intval(b); }) : 0; // total on page info = api.column(4, { page: 'current' }).data(); pagetotal = data.length ? data.reduce(function (a, b) { homecoming intval(a) + intval(b); }) : 0; // update footer $(api.column(4).footer()).html( '$' + pagetotal + ' ( $' + total + ' total)' ); } }); }; i want pass saletotal datatable or view
how can pass saletotal controller view. tried many ways still problem not solved.
if understand correctly info want info saletotal method.
that info in json returned allsalereport method:
return json(new { ... salesreturn = saletotal(fromdate, todate) }, so when phone call allsalereport datatable utilize fnserverdata override function gets info , insert want it. like:
"fnserverdata": function (ssource, aodata, fncallback) { $.getjson(ssource, aodata, function (result) { var saletotal = result.salesreturn; // insert saletotal in footer fncallback(result); }); }, asp.net-mvc asp.net-mvc-4 datatable asp.net-mvc-5 jquery-datatables
Comments
Post a Comment