jquery - Post to controller and get result event checked -
i try result :
function getprice() { var url = '@url.action("getadditionalprice")'; $.post(url, { additionalsid: $("input[name=selectedadditionals]").val }), function(data) { $("#totalamount").val(data); }; //view } public actionresult getadditionalprice(string[] additionalsid) { decimal price = 0; foreach (var id in additionalsid) { var aid = int.parse(id); price += db.contractadditionals.where(ca => ca.contractadditionalid == aid).select(ca => ca.price).single(); } return json(price, jsonrequestbehavior.allowget); }//controller
why string[] additionalsid
parameters undefined? how post parameter controller , set result #totalamount
?
try this
function getprice() { var url = '@url.action("getadditionalprice")'; $.post(url, { additionalsid: $("input[name=selectedadditionals]").val() }), function(data) { $("#totalamount").val(data.result); }; //view } public actionresult getadditionalprice(string[] additionalsid) { decimal price = 0; foreach (var id in additionalsid) { var aid = int.parse(id); price += db.contractadditionals.where(ca => ca.contractadditionalid == aid).select(ca => ca.price).single(); } return json(new {result=price}, jsonrequestbehavior.allowget); }//controller