我会尝试得到这样的结果:
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
为什么string[] additionalsId
参数总是未定义?如何将参数发布到控制器并将结果设置为#TotalAmount
?