Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6345083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:45:17+00:00 2026-05-24T20:45:17+00:00

If I am using the ASP.net MVC standard list view is there an easy

  • 0

If I am using the ASP.net MVC standard list view is there an easy way to create totals in the view? I can copy the standard list code in here but I am not doing anything fancy here.

I “could” do the totals as another object in the model going to the view but then it would still need to somehow be handled in the view.

What I have now looks sort of like:

      ColA colb ColC
Item   1     1    2 
Item   2     1    2 

What I want is:

      ColA colb ColC
Item   1     1    2 
Item   2     1    2 
Total  3     2    4
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:45:18+00:00Added an answer on May 24, 2026 at 8:45 pm

    While it might be trivial to sum up these totals right in the view, I have always opted to put these totals right in my ViewModel for the view. This gives me the ability to unit test that my totals are accurate. If the logic for the totaling was done in the view, there would be no easy way to test such a thing. This keeps the view logic simple and limited to displaying values, not doing the “logic” necessary to sum values up.

    Taking this to the next level, what if the rules for a “total” were that negative amounts don’t “count” toward the total? Then the view would be responsible for not only knowing how to sum the items, but also needs to be aware of the “don’t count negative values” business rule. I find it’s best to let the server do as much of the work as it can, and making the view as “simple” (thin) as possible.

    In your example, I may have a ViewModel that looks like:

    Public Class MyViewModel
        Public Property Columns As List(Of ColInfo)
        Public Property Items As List(Of RowItem)
    End Class
    
    Public Class ColInfo
        Public Property Id As Guid
        Public Property Name As String
        Public Property ColTotal As Integer
    End Class
    
    Public Class RowItem
        Public Property Name As String
        Public Property ColValues As Dictionary(Of Guid, Integer)) ' Value lookup for each column
        Public Property RowTotal As Integer
    End Class
    

    (Note, I added a “Row Total” to my example as well, in addition to the column totals.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ASP.Net MVC 2, is there any way to use the RedirectToAction() method of
I've got a standard ASP.NET MVC form post. eg. <% using (Html.BeginForm<CommentController>(c => c.Create()))
I need to create a web application using ASP.NET MVC, jQuery and web standards
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,
I'm building an asp.net MVC 2 app. I have a list view which lists
I've started using Ninject in an ASP.NET MVC 3 project, using the standard boot
I'm using asp.net mvc 3 with jquery unobtrusive validation. I recently changed from standard
Why would you consider using ASP.Net MVC or standard ASP.Net with forms and controls
I'm deciding between using ASP.NET MVC, or standard ASP.NET Web Forms with URL routing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.