c# - 在 asp.net mvc 中创建多级评论系统

标签 c# asp.net-mvc

我目前正在写一个用 asp.net mvc 编写的博客。我有一张表,用以下模型存储评论

public partial class Comment
    {
        public int CommentId { get; set; }
        public string Comment { get; set; }
        public System.DateTime CommentDate { get; set; }
        public int AuthorId { get; set; }
        public int PostId { get; set; }
        public int CategoryId { get; set; }

        public virtual Category Category { get; set; }
        public virtual Post Post { get; set; }
        public virtual UserProfile UserProfile { get; set; }
    } 

目前评论仍然是一级评论,即用户不能回复评论。我怎样才能实现一个多级评论系统,使评论可以有回复,回复可以有另一个回复等等。

最佳答案

添加引用 Comments 表的 parentCommentId 列。 之后在每个回复中:

  1. 如果是直接回复帖子,请将 parentCommentId 列留空
  2. 如果是对先前发表的评论的回复,请将该评论 ID 放入此列。在这种情况下,您可以将 postid 列留空或不留空。这取决于你的喜好!

关于c# - 在 asp.net mvc 中创建多级评论系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27710025/

相关文章:

c# - .Net 是否为每个 dll 和 exe 创建 1 个堆栈(用于存储值类型)或每个程序创建 1 个堆栈

c# - 如何计算图表的趋势线?

c# - 将数据库从本地更改为 azure 不起作用

sql-server - 如何检查 ASP.NET MVC4 应用程序性能?

c# - 数组有字符串值,我想要一个整数

c# - 代码中的 ASP.NET Core appsettings.json 更新

c# - 如何限制 FFMpeg CPU 使用率?

.net - Entity Framework 二级缓存

javascript - 如何在 C#/asp.Net/Razor 中异步获取用户键盘输入

asp.net-mvc - MVC 和 AngularJS 路由 - 403.14 - 禁止访问