I have a controller with a method that returns a value:
public float GetShoppingCartTotal()
{
string user = User.Identity.Name;
var total = _context.ShutterOrders.Where(c => c.User == user).Select(c => c.Price * c.Amount).Sum();
return total;
}
How can I call this method from a view so I can show its value, here is my view (P.S. I took out some code of the view since I think it really is unnecessary for the purpose of this question. I have marked the part where I would like to call my controller function):
@model IEnumerable<ShuttersInc.Areas.Identity.Data.ShutterOrders>
<tfoot>
<tr>
<td colspan="3" class="text-right">Total:</td>
<td class="text-right">
**I'd like to place it here**
</td>
</tr>
</tfoot>
P.P.S - I have an IEnumerable model since I list items from a list. I think this is one of the main problems why I can't call the method from the controller, although I might be mistaken.
question from:
https://stackoverflow.com/questions/65874045/how-can-i-call-a-controller-method-in-a-view-using-asp-net-core 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…