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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:23:25+00:00 2026-06-17T17:23:25+00:00

I have Comment model like this: public class Comment { public int? ParentId {

  • 0

I have Comment model like this:

public class Comment
    {
        public int? ParentId { get; set; }
        public string Text { get; set; }
        public int ProjectId { get; set; }
        public int UserWhoTypeId { get; set; }
    }

I want to show comments one under another by parentID . Parent Comments will seems in div, child Comments will seems in

<ul>
   <li>
      child comments go here
   </li>
</ul>

For example,

  <ul>
       <li>
          <div>
               parent comments go here
          </div>
          <ul>
             <li>
                 child comments go here
             </li>
           </ul>
       </li>
  </ul>

I firstly need to collect Comments with LINQ like tree and then apply it like shown above in view. Any links or advice please.

Edit:

I created model as

public class CommentListModel
{
    public Comment Comment{ get; set; }
    public List<Comment> Childs { get; set; }
}

And I collected all comments in 1 list:

List<CommentListModel>  CommentHierarchy = MyService.GetCommentHierarchy();

Now, I need to show CommentHierarchy in view like tree hierarchy. Please help.

  • 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-06-17T17:23:26+00:00Added an answer on June 17, 2026 at 5:23 pm

    You can change the “Childs” Property of CommentListModel to be a collection of CommentListModel like so:

    public class CommentListModel
    {
        public Comment Comment { get; set; }
        public List<CommentListModel> Childs { get; set; }
    }
    

    Create a partial view as a display template (put file under DisplayTemplates folder) for CommentListModel:

    @model CommentListModel
    <ul>
        <li>
            <div>@Html.DisplayFor(m => m.Comment.Text)</div>
            @Html.DisplayFor(m => m.Childs)
        </li>
    </ul>
    

    Then in your parent view, simply call:

     @Html.DisplayFor(m => m)
    

    Assuming the model of the parent view is a collection of CommentListModel objects.

    This will allow your list to recurse as deeply as your collection goes.

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

Sidebar

Related Questions

Given a model like this: public class Location { public int Id { get;
I have a domain model that includes something like this: public class Customer :
I have a model that looks something like this: class Comment < ActiveRecord::Base ...
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):
I have a partial class in a dbml file. public partial class Comment string
I have a type: public class IssueForm { Order Order {get; set;} Item Item
I have an object that looks like this: [Bindable] public class MyRecord implements ValueObject
I have a data model where a User can like a Project, Suggestion, Comment
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
I have this link @Ajax.ActionLink(comment, CreateDebateComment, new { id = Model.DebateID}, new AjaxOptions {

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.