Skip to content
Advertisement

How can I count total item in an object/record and count only the value = true

obj = {true, false, false , true,…}; This is only one record that I query from database by using Linq

The reason is I would like to display Finsished 2 of 7 , that is why I need to count items in a record. Thank you in advance!

After I can store numbers in variable, then I would like to display like this”Finished 2 of 7″

Advertisement

Answer

My solution involves 2 parts first. Create a ViewModel to get the number of completed object that associates with the class that goes:

Note that this View Model would calculate the number of completed subject of each Module_Completion Class and then from your controller. You just need to do something like this

You can also achieve this by creating a function in SQL database as well. Another piece of advice is that, do consider stop using underscrore in your data table and data field. Follow the latest convention, the next person who take over your code will appreciate that.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement