Skip to content

Instantly share code, notes, and snippets.

@davecowart
Created February 23, 2012 16:51
Show Gist options
  • Save davecowart/1893715 to your computer and use it in GitHub Desktop.
Save davecowart/1893715 to your computer and use it in GitHub Desktop.
Nested Comments
@model FollowMyBuild.Web.Models.ViewModels.Portable.PortableComment
<section class="project_comment">
<span class="comment_author">@Model.AuthorName</span>
<span class="comment_timestamp">@Model.Timestamp.ToLongTimeString()</span>
<p>@Model.Body</p>
</section>
@using FollowMyBuild.Web.Models.ViewModels.Portable
@model IEnumerable<PortableComment>
<div id="comments">
@foreach (var comment in Model.Where(c => !c.ReplyTo.HasValue)) {
@Html.Partial("_RecursiveComment", new PortableRecursiveComment { Id = comment.Id, Comments = Model })
}
</div>
@using FollowMyBuild.Web.Models.ViewModels.Portable
@model PortableRecursiveComment
@Html.Partial("_Comment", Model.Comments.FirstOrDefault(c => c.Id == Model.Id))
<div class="comment_indent" style="margin-left: 15px;">
@foreach (var childComment in Model.Comments.Where(c => c.ReplyTo == Model.Id)) {
@Html.Partial("_RecursiveComment", new PortableRecursiveComment { Id = childComment.Id, Comments = Model.Comments })
}
</div>
using System.Collections.Generic;
namespace FollowMyBuild.Web.Models.ViewModels.Portable {
public class PortableRecursiveComment {
public PortableRecursiveComment() {
Comments = new List<PortableComment>();
}
public int Id { get; set; }
public IEnumerable<PortableComment> Comments { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment