I have a view where I store late fees for books not returned on time, here is how I do it in controller action:
[HttpPost()]
public ActionResult DisplayTotalBalance(string id)
{
DataContext db = new DataContext();
var totalLateFee = (from p in db.vwCustomer.Where(a => a.CustomerId == id)
group p by p.LateFee into g
select g.Key).FirstOrDefault();
return Json(new { totalLateFee });
}
Here in vwCustomer where I store late fees, a customer may have many late fees listed. For e.g.
CustomerId LateFee
J101 5.0
P202 6.0
J101 2.0
P203 5.0
J101 5.0
How can I sum all the LateFee for J101 and return in controller action?
1 Answer