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

  • Home
  • SEARCH
  • 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'm trying to group one variable of my data by another and then plot
.NET balanced group regexes make my head explode. I've got this string i'm trying
I am trying to think data in terms of sets but have some questions
I'm trying to work on data from .csv files of known general format but
While trying to extract data from a view by joining it with two other
I'm trying to get this LINQ to work but fails with the error. Cannot
I'm trying to reorder/group a set of results using SQL. I have a few
Trying to figure out an equation to get the current group a page would
My group is developing a service-based (.NET WCF) application and we're trying to decide
I'm trying to set the group type for a new Active Directory Entry via

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.