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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:28:35+00:00 2026-05-20T22:28:35+00:00

I have a big problem, at least for me. I have a Table with

  • 0

I have a big problem, at least for me.
I have a Table with categories and unlimited subcategories.
The table looks like this:

ID Parent_ID Name

1 null riding

2 1 gallopa

3 null figure

4 2 trapper

And there is a table containing items wich are attributed to a category.
The table looks like this:

ID cattegory_ID Name

1 4 fast

2 1 slow

3 3 high

4 2 low

Now I want to retrieve them from the database and show them in my mvc2 application like this:
A Fieldset for the first category, and one for the subcategory in the fieldset before. The items should be listed in the fieldset with checkboxes.
https://i.stack.imgur.com/lyMWD.png

I like to work with @Html.CheckBoxfor.

Has any one got any idea? I’m working on this problem since last week without a result.
I tried to solve the problem recursively but it did not work.
An example would be beautiful, thanks a lot!

Thanks a lot for your answer!
Everything works fine! But how to do a Httppost with this model? And how to get the Status Checked or not Checked of every checkbox?

here is my start:

   [HttpPost]
    public ActionResult CreateNewHorse(NewHorseModel collection)
    {
      collection.Cattegories.Count(); <------------is always null! Why?
    }
  • 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-20T22:28:36+00:00Added an answer on May 20, 2026 at 10:28 pm

    You could create a PartialView that has the Category-class as a Model, something like this:

    Category.cshtml

    @model Category
    
    <fieldset>
        <legend>@Model.Name</legend>
        @foreach (var item in Model.Choices)
        {
            Html.RenderPartial("Choice", item);
        }
    
        @foreach(var item in Model.Subcategories)
        {
            Html.RenderPartial("Category", item);
        }
    </fieldset>
    

    Choice.cshtml

    @model StackOverflow_Tester.Models.Choice
    
    <p>@Html.LabelFor(m => m.Selected) @Html.CheckBoxFor(m => m.Selected)</p>
    

    in your main view, you’d simply render the partialview based on the categories:

    @foreach (var item in Model)
    {
        Html.RenderPartial("Category", item);
    }
    

    Now you need to pass only the root categories into your view

    This should give you a recursive view with categories and/or subcategories.

    UPDATE

    The viewmodel/model could look like this:

    Category.cs

    public class Category
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<Category> Subcategories { get; set; }
        public List<Choice> Choices { get; set; }
        public Category Parent { get; set; }
    }
    

    Choice.cs

    public class Choice
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool Selected { get; set; }
    }
    

    I’ve updated the code in the top as well, to reflect this Model

    Hope this helps!

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

Sidebar

Related Questions

I have this big data-entry sort of page, a table kind of layout using
I have this query in MS SQL which is acting very weird (at least
I have one BIG table(90k rows, size cca 60mb) which holds info about free
I have had a few problems with log files growing too big on my
I have big issue with url-rewriting for IIS 7.0. I've written simple module for
How would you maintain the legacy applications that: Has no unit tests have big
I have a big string (let's call it a CSV file, though it isn't
i have a big web application running in perl CGI. It's running ok, it's
I have a big load of documents, text-files, that I want to search for
I have a big lump of binary data in a char[] array which I

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.