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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:18:32+00:00 2026-05-26T20:18:32+00:00

I have a multi-level dropdown menu on my MVC Application and I’m trying to

  • 0

I have a multi-level dropdown menu on my MVC Application and I’m trying to sort the products by brand, gender and type. My menu looks like this:

    <li>Man
            <ul>
                <li><h2>By Type</h2></li>
                <li>CATEGORY</li>
            </ul>
            <ul>
                <li><h2>By Brand</h2></li>
                <li>BRAND</li>
            </ul>   
        </div>
    </li>
    <li>
    <li>Woman
            <ul>
                <li><h2>Categories</h2></li>
                <li>CATEGORY</li>
            </ul>
            <ul>
                <li><h2>Brands</h2></li>
                <li>BRAND</li>
            </ul>   
        </div>
    </li>
    <li>

and here is one of my controllers:

    public ActionResult Man(int type)
    {
        var productTypeModel = storeDB.Categories.Include("Products")
            .Single(g => g.CategoryId == type);

        return View(productTypeModel);
    }

This is the partialview that loads into the menu:

@model IEnumerable<Store.Models.Category>
<ul>
<li><h2>By Type</h2></li>
@foreach (var type in Model)
{
    <li>@Html.ActionLink(type.Name,
            "Man", "Store",
            new { Category = type.CategoryId }, null)
    </li>
}
</ul>

Is there any way that I can display only the categories and brands that have products associated with each gender using lambda expressions? I mean, I don’t want “skirt” to appear on “By Type” when I’m browsing products for man and I don’t want a brand that has products for man appearing on the ladies section.

  • 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-26T20:18:33+00:00Added an answer on May 26, 2026 at 8:18 pm

    You could use GroupBy:

    public ActionResult Menu()
    {
        var model =
            from p in storeDB.Products.Include("Category").Include("Type")
            group p by p.Gender
            into genderGroup
            select new MenuObject
            {
                Gender = genderGroup.Key,
                Categories =
                (
                    from p2 in genderGroup
                    group p2 by p2.Category
                    into categoryGroup
                    select categoryGroup.Key
                ),
                Types =
                (
                    from p3 in genderGroup
                    group p3 by p3.Type
                    into typeGroup
                    select typeGroup.Key
                )
            };
    
        return View(model);
    }
    
    public class MenuObject
    {
        public string Gender { get; set; }
        public IEnumerable<Category> Categories { get; set; }
        public IEnumerable<Type> Types { get; set; }
    }
    

    And then in the template:

    @foreach (var item in Model)
    {
        <li>@item.Gender
            <ul>
                <li><h2>By Category</h2></li>
                @foreach (var category in item.Categories)
                {
                    <li>@Html.ActionLink(category.Name,
                            "ByCategory", "Store",
                            new {
                                Gender = item.Gender,
                                Category = category.ID,
                            }, null)</li>
                }
            </ul>
            <ul>
                <li><h2>By Type</h2></li>
                @foreach (var type in item.Types)
                {
                    <li>@Html.ActionLink(type.Name,
                            "ByType", "Store",
                            new {
                                Gender = item.Gender,
                                Type = type.ID,
                            }, null)</li>
                }
            </ul>
        </li>
    }
    

    This would produce something like:

    <li>Man
        <ul>
            <li><h2>By Category</h2></li>
            <li><a href="/Store/ByCategory/Man/2/">Sports</a></li>
            <li><a href="/Store/ByCategory/Man/3/">Underwear</a></li>
        </ul>
        <ul>
            <li><h2>By Type</h2></li>
            <li><a href="/Store/ByType/Man/1/">Boxer Shorts</a></li>
            <li><a href="/Store/ByType/Man/2/">Socks</a></li>
        </ul>
    </li>
    <li>Woman
        <ul>
            <li><h2>By Category</h2></li>
            <li><a href="/Store/ByCategory/Woman/1/">Running</a></li>
            <li><a href="/Store/ByCategory/Woman/2/">Sports</a></li>
            <li><a href="/Store/ByCategory/Woman/3/">Underwear</a></li>
        </ul>
        <ul>
            <li><h2>By Type</h2></li>
            <li><a href="/Store/ByType/Woman/2/">Socks</a></li>
            <li><a href="/Store/ByType/Woman/3/">Bra</a></li>
        </ul>
    </li>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On SQL Server 2005, I have a complex multi-level allocation process which looks like
How can I do a multi-level parent-child sort using Linq if I have a
I have a multi-level mega menu on my site (using jquery plugin), however, when
Consider we have a multi-level html list that looks like this: <ul class=catalog> <li>
I have jQuery menu I've been working on based on Stu Nicholls CSS multi-level
I'm trying to build a multi-level dropdrown CSS menu for a website I'm doing
I have a multi-level nav styled as an unordered list that looks like this:
I am trying to build a multi-level dropdrown menu, I'm using umbraco cms. What
I have a drop-down/multi-level CSS menu on a page. The menu however doesn't appear
I'm trying to build a simple multi-level UL Horizontal Accordion (or slide menu) 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.