How to show a query in a view

Jadoka

New member
Joined
May 18, 2022
Messages
3
Programming Experience
Beginner
Oops, good afternoon. I'm creating my first CRUD in C# using .NET CORE 6(MVC) and I have a question. I managed to do the CRUD, but I would like to know how to show in one of the View the select of the sum of a column.
Basically I have an Employee table with some columns, and in one of them, there is the "empcode" column. I wanted to do the sum of the values in this column and show it in a view. If anyone can show me how, I'd be grateful.
1653075060458.png
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,711
Location
Chesapeake, VA
Programming Experience
10+
Somewhere in your view's CSHTML, you would have an element is bound to a property from your model. In your model, you would store the sum of the column. You would presumably set that property either when the model is being updated/created, or dynamically by computing on the fly.
 

Jadoka

New member
Joined
May 18, 2022
Messages
3
Programming Experience
Beginner
Somewhere in your view's CSHTML, you would have an element is bound to a property from your model. In your model, you would store the sum of the column. You would presumably set that property either when the model is being updated/created, or dynamically by computing on the fly.
Can you show my a exemple?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,711
Location
Chesapeake, VA
Programming Experience
10+
In StackOverflow, they show a third approach: dynamically compute in the controller and put the value in the viewbag:

 
Top Bottom