Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<tbody>
                                                               @{int srno2 = 0;}
                                                               @foreach (College.Core.ViewModels.SGPA.ExamsViewModel _Exams in _subject.GetExams())
                                                               {
                                                                   srno2 += 1;
                                                                   <tr>
                                                                       <td>@srno2</td>
                                                                       <td>@_Exams.ExamType</td>
                                                                       <td>@_Exams.ObtainedMark</td>
                                                                       <td>@_Exams.OutOfMarks</td>

                                                                       @if(@_Exams.TotalLectureConducted == null)
                                                                       {
                                                                           <td>0</td>
                                                                       }
                                                                       else
                                                                       {
                                                                           <td>@_Exams.TotalLectureConducted</td>
                                                                       }
                                                                       @if(@_Exams.NoOfLectureAttended == null)
                                                                       {
                                                                           <td>0</td>
                                                                       }
                                                                       else
                                                                       {
                                                                           <td>@_Exams.NoOfLectureAttended</td>
                                                                       }
                                                                       @if(@_Exams.AverageAttendance == null)
                                                                       {
                                                                          <td>0%</td>
                                                                       }
                                                                       else
                                                                       {
                                                                          <td>@_Exams.AverageAttendance%</td>
                                                                       }

                                                                   </tr>
                                                               }
                                                           </tbody>
                                                           <tfoot>

                                                               <tr>
                                                                   <td colspan="4" align="right">Total</td>
                                                                   <td>SUM-TotalLectureConducted</td>
                                                                   <td>SUM-NoOfLectureAttended</td>
                                                                   <td>(SUM-TL/SUM-NLA)*100</td>

                                                               </tr>

                                                           </tfoot>


What I have tried:

NO	Exam 	   Mark	Out	  TL	 NLA	  AV
1	End Tem	   12	60	   5	 5	    100%
2	Internal 1 10	20	   3	 1	    33%
3	internal 2 10	20	   4	 2	    50%
                    Total  12    8	    66%

TL-TotalLectureConducted
NLA-NoOfLectureAttended

I want to this format of result 
please help me
Posted
Updated 3-Dec-19 3:05am
Comments
Richard MacCutchan 30-Nov-19 6:01am    
Look at your desired outpu. From that you can see how many columns are required and what value each should contain. Your table layout just needs to match those requirements, so write it out on paper before creating your actual code.

1 solution

Sum the values within the loop, and output the totals in the footer.

Obviously you'll need to calculate the total average from the other totals.
Razor
<tbody>
    @{
        int srno2 = 0;
        double tl = 0, nla = 0;
    }
    @foreach (College.Core.ViewModels.SGPA.ExamsViewModel _Exams in _subject.GetExams())
    {
        srno2 += 1;
        tl += _Exams.TotalLectureConducted.GetValueOrDefault();
        nla += _Exams.NoOfLectureAttended.GetValueOrDefault();
        
        <tr>
            <td>@srno2</td>
            <td>@_Exams.ExamType</td>
            <td>@_Exams.ObtainedMark</td>
            <td>@_Exams.OutOfMarks</td>
            <td>@_Exams.TotalLectureConducted.GetValueOrDefault()</td>
            <td>@_Exams.NoOfLectureAttended.GetValueOrDefault()</td>
            <td>@_Exams.AverageAttendance.GetValueOrDefault()%</td>
        </tr>
    }
</tbody>
<tfoot>
    <tr>
        <td colspan="4" align="right">Total</td>
        <td>@tl</td>
        <td>@nla</td>
        
        @if (tl == 0)
        {
            <td>(N/A)</td>    
        }
        else
        {
            double av = nla / tl;
            <td>av.ToString("P")</td>
        }
    </tr>
</tfoot>
 
Share this answer
 
Comments
Maciej Los 3-Dec-19 9:22am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900