0
I have a model with category
, Deposit
, Date
, Amount
, I need the Amount
add all the deposit
that exist in the database and returns in the View
, I did the following, only it didn’t solve.
public async Task<ViewResult> Amount()
{
var movements = _context.Movement.Include(x => x.Deposit).ToList();
var total = movements.Sum(x => x.Amount);
ViewData["amount"] = total;
return View(total);
}
I am passing the following parameter in View:
@ViewData["amount"]
Add your View code so we know how you are trying to access this information.
– Talles Santana
@Tallessantana Hello, I modified.
– Matheusls
You are passing the amount twice to the view. Both in her Model and in Viewdata. Viewdata I think you need to cast so arrobaViewData["amount"] as Int32 can work. Another option is not to use Viewdata but the model. To do this, in the first line of your view add int arrobamodel Where you want to use the value use arrobamodel or arrobamodel
– Talles Santana