I have a page that displays a list of contracts. Each row contains an Amount, a Fee, and a Total that I'm calculating row that row.
I'm also trying to calculate a grand total, that sums up Total from the collection.
Here's what I have:
var contracts = _contractsRepository.Contracts.
Select(c => new ContractViewModel
{
ContractId = c.ContractID,
Amount = c.Amount,
Fee = c.Fee,
Total = c.Sum(cc => cc.Amount) + c.Sum(cc => cc.AdminFee)
});
// error here
ViewBag.GrandTotal = contracts.Sum(c => c.Total).ToString().Format("{0:c}");
I get a compilation error when I try to calculate the grand total that says:
Member 'string.Format(string, params object[])' cannot be accessed with an instance reference; qualify it with a type name instead
Anyone know what I can do to fix this?