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 678543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:09:41+00:00 2026-05-14T01:09:41+00:00

I am trying to group a data collection and send it to the View

  • 0

I am trying to group a data collection and send it to the View where it needs another level of grouping I tried doing this in the Model level but looping throug the grouped collection becomes very difficult and determining the data type to pass to a partial is not easy

Grouping at the View level looks easy to implement but I want to avoid this is there a way to do this?

code: the model is a collection of Restaurants which should be grouped by category first and then by name to get different address

 <% foreach (var categoryGroup in Model.GroupBy(r => r.RestaurantCategory)){%>

    <h1><%=categoryGroup.Key %></h1>

            <% foreach (var restaurant in categoryGroup.GroupBy(c => c.RestaurantName)){%>
                <%Html.RenderPartial("Restaurant", restaurant); %>
            <%}%>
    <%}%> 

Partial Code:

<ul class="addressList">
<%foreach (var address in Model){%>
<li>

    <%= Html.Encode(address.Address1)%>
    <%= Html.Encode(address.City)%>   
    <%=string.Format("<a href='http://www.bing.com/maps/default.aspx?where1={0}' target='_blank'> Get Directions</a>", address.FullAddress)%> 
</li>
<%}%>

</ul>
  • 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-14T01:09:41+00:00Added an answer on May 14, 2026 at 1:09 am

    Grouping at the View level looks easy
    to implement but I want to avoid this
    is there a way to do this?

    Why is this a problem exactly? The model layer should not have implementation details for the view. It should simply have the data which is to be used by the view to present information to your users. There is no reason why another view couldn’t use the same model to display the data in a different manner. If you would like to do your data formatting somewhere other than the view, you need to add another layer, like an off shoot of the view model concept.

    Since the view is displaying the data, do the grouping in the view. There are only a few reasons I might change that, most of which would be customer initiated.

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

Sidebar

Related Questions

I am trying to group some data without much luck. I have a list
I am trying to figure out how to group data contained inside a Table.
I'm trying to group a set of data based on the range of an
I'm trying to create a data extractor algoritm from group buying sites to build
I'm trying to understand how LINQ can be used to group data by intervals
I am trying to group row data from a 3-dimensional array by a column
I've got this code I'm trying to use to export data from Excel to
I have spent almost 24hours trying to figure out what I'm doing wrong, but
I'm trying to group data in time periods. Each period is 5 minutes and
I am trying to use link to group data and use it directly in

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.